shocker-z Posted December 30, 2006 Share Posted December 30, 2006 Morning all,I'm confused on this one ladiers and gents..If i call my function with [code]getdist('postcode', 'postcode');[/code]oviusly postcode is really a propper postcode, it works finebut.. if i call the function with[code]getdist($to, $from);[/code]it doesn't work.. i've tryed renaming the variables JUST in case somehow they conflicked but with no joy.I have also echo'ed the variables back into main windows and copied and pasted directly as a string and work so the variables are correct and also the postcodes are located on multimap.My full code[code]<?phpfunction getdist($to,$from) {$to=str_replace(' ','',$to);$from=str_replace(' ','',$from);//get file content $multimap=file_get_contents("http://www.multimap.com/map/aproute.cgi?client=public&lang=&rn=GB&input_rt=aproute_pan&startcountry=GB&startrd=&starttown=&startpc=$from&endcountry=GB&endrd=&endtown=&endpc=$to&qs=q&starttime=13%3A52");//Narrow to sniplet $place1=strpos($multimap,'<dt>Total distance:</dt>'); $place2=strpos($multimap,'<dt>Number of steps:</dt>'); $distance = substr($multimap, $place1, $place2-$place1); //get distance $dist1 = strpos ($distance, '<dd>'); $dist2 = strpos ($distance, ' ', $dist1); $totaldist = substr($distance, $dist1+4, $dist2-($dist1+4)); $totaldist=str_replace("\n",'',$totaldist);//return miles return $totaldist;}include('header.php');$clientID=mysql_escape_string($_POST['location']);$getclient=mysql_query("SELECT postcode FROM clients WHERE ID = '$clientID'");$client=mysql_fetch_array($getclient);$to=$client['postcode'];$engineers=mysql_query("SELECT * FROM names");mysql_query('truncate table tempmiles');while ($engineer = mysql_fetch_array($engineers)) { $getclient=mysql_query("SELECT postcode FROM clients WHERE ID = '$engineer[clientID]'"); $client=mysql_fetch_array($getclient); $from=$client['postcode']; $tempmiles=getdist($to, $from);//echo to check that $to and $from are set correctly echo "Engineer: $engineer[name] Miles: $tempmiles From: $from To: $to <Br>"; mysql_query("INSERT INTO tempmiles (name, miles) VALUES('$engineer[name]','$tempmiles')") or die(mysql_error()); }?>[/code]RegardsLiam Link to comment https://forums.phpfreaks.com/topic/32269-function-will-accept-string-but-wont-accept-vars/ Share on other sites More sharing options...
fert Posted December 30, 2006 Share Posted December 30, 2006 try replacing $from with {$from} and $to with {$to} Link to comment https://forums.phpfreaks.com/topic/32269-function-will-accept-string-but-wont-accept-vars/#findComment-149794 Share on other sites More sharing options...
shocker-z Posted December 30, 2006 Author Share Posted December 30, 2006 Nope i've tryed that but still not working..The weird thing is that if i set $to and $from like $from='NG16 3SB'; $to='NG1 5EJ'; $tempmiles=getdist($to, $from);which are postcodes directly from the database which I echoed back, then it all works fine :SCan't understand why as like I say it's a direct copy paste of the postcode!I even echoed the postcodes back enclosed in [] and it shew that there was a space at the end of the postcode but this still caused no problems when tested as a stringEDIT:I tryed this[code] $from=str_replace(' ','',$from); $to=str_replace(' ','',$to); $tempmiles=getdist($to, $from);//echo to check that $to and $from are set correctly echo "Engineer: $engineer[name] <Br> Miles: $tempmiles <Br>From: [$from] To: [$to] <Br><Br><Br>"; [/code]and the postcode echoed as From: [NG163SB ] To: [NG15EJ ] so would seem that there is some special char still in the postcode..ANOTHER EDIT:[code] $from=mysql_real_escape_string($from); $to=mysql_real_escape_string($to);[/code]show's Engineer: Liam WheldonMiles:From: [NG163SB\r\n] To: [NG15EJ\r\n] but then the next record show'sFrom: [NG92LF\r\n] To: [NG15EJ\\r\\n] and next From: [NG210RT\r\n] To: [NG15EJ\\\\r\\\\n] and so on..any ideas?RegardsLiam Link to comment https://forums.phpfreaks.com/topic/32269-function-will-accept-string-but-wont-accept-vars/#findComment-149798 Share on other sites More sharing options...
shocker-z Posted December 30, 2006 Author Share Posted December 30, 2006 Solvedused trim()Liam Link to comment https://forums.phpfreaks.com/topic/32269-function-will-accept-string-but-wont-accept-vars/#findComment-149810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.