Jump to content

[SOLVED] Error with file() and dynamic links.


Recommended Posts

I'm having a problem opening a web page where i have to generate the url.

 

$url= 'http://www.example.org/webservices/application.cfm?BEDROOMS=' . $bedrooms .'&HOWMANYPEOPLE=' . $howmanypeople . '&KINDOFBUILDING=' . $kindOfBuilding . '&STATE=' . $state . '&qtyToCalculate=' . $qtyToCalculate;


$data = implode("", file($url));

 

This works fine, if i echo the url, and copy paste the link into a browser.

The link works. And if I paste the link that echo spits out in ("", file("")); It also works just fine.

 

A quick overview is, this website generates an xml file when variables are passed to it via the url. I'm trying to then pull that xml file down, and parse it to display data.

 

Also, this website is a "Web service" So i don't have access to the actual cold fusion code.

 

Any help would be greatly appreciated.

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/
Share on other sites

Yeah, it would be. It just doesn't display anything. If I use the actual built out link, it pulls the xml file down just fine. Its only when i am trying to build the link dynamically.

 

I'm curious if anyone knows of a problem with passing a filename to file() that is made up of several variables, if it breaks?

 

heres the full function:

 

function readDatabase($filename)
{
    // read the XML database of carboncalculators
    $data = implode("", file($filename));
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $tags);
    xml_parser_free($parser);

    // loop through the structures
    foreach ($tags as $key=>$val) {
        if ($key == "carboncalculatorsresults") {
            $molranges = $val;
            // prase data
            for ($i=0; $i < count($molranges); $i+=2) {
                $offset = $molranges[$i] + 1;
                $len = $molranges[$i + 1] - $offset;
                $tdb[] = parseMol(array_slice($values, $offset, $len));
            }
        } else {
            continue;
        }
    }
    return $tdb;
}

 

 

I'm sending $url to that function, and having $url be defined as:

 

$url= 'http://www.example.org/webservices/application.cfm?BEDROOMS=' . $bedrooms .'&HOWMANYPEOPLE=' . $howmanypeople . '&KINDOFBUILDING=' . $kindOfBuilding . '&STATE=' . $state . '&qtyToCalculate=' . $qtyToCalculate;

 

Doesn't work. But having $url defined as:

 

$url= "http://www.example.org/webservices/application.cfm?BEDROOMS=4&HOWMANYPEOPLE=10&KINDOFBUILDING=Big%20apartment%20building%20(more%20than%2015%20units)&STATE=Alabama&qtyToCalculate=2";

 

does work.

 

 

Thanks for the help darkfreaks,

 

Unfortantly, I'm getting the same result.

 

After some more thought on the issue, and looking at the "Correct" url, i'm realizing that the variable names the web service requires has spaces in them. These spaces are automatically converted to %20 in a url in a web browser, but my guess is, that isn't happening in php. And the file() call is breaking as soon as it see's a white space.

 

Does anyone know an easy way to convert all the white spaces into url friendly %20's?

 

Thanks, in advance.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.