agentq Posted October 13, 2007 Share Posted October 13, 2007 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, Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/ Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 what are you trying to implode? implode joins things in an array are you sure you dont need? <?php $data = explode("", file($url));?> Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368282 Share on other sites More sharing options...
agentq Posted October 13, 2007 Author Share Posted October 13, 2007 Right, I'm imploding the array into a string, for output. Was an easy way to see if it pulled in all the data from the xml before I started trying to parse the array. Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368286 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 oh i see LOL it reads it into an array Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368287 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 would be nice if there was an actual problem or erro? Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368289 Share on other sites More sharing options...
agentq Posted October 13, 2007 Author Share Posted October 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368293 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 <?php $data = implode("",$url); /// joins the url $data = file($url); /// reads the joined url echo $data; /// echos it ?> Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368300 Share on other sites More sharing options...
agentq Posted October 13, 2007 Author Share Posted October 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368317 Share on other sites More sharing options...
agentq Posted October 13, 2007 Author Share Posted October 13, 2007 Ah, that was the problem. The more obvious approach was to add the %20's to the variables on the form. Worked like a charm! Thanks for the help darkfreaks. Quote Link to comment https://forums.phpfreaks.com/topic/73028-solved-error-with-file-and-dynamic-links/#findComment-368324 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.