fife Posted March 4, 2012 Share Posted March 4, 2012 Hi. I am try to implement a go dynamic google maps feature into my website. If i put a static address into my code it works great. If then I use a variable it all goes wrong. Here is the line Im having trouble with. $address = ' address'; $address = urlencode($address); //so here is the static version that works great!!!!!!!!!!!!!!!!!!! $address = ' 45 chapel road, preston, lancashire, pr4 6rt, uk'; $address = urlencode($address); // and a version that does not work. $address = '$addressL1, $area, $county, $postcode, $country'; $address = urlencode($address); // another that does not work $address = ' {$addressL1}, {$area}, {$county}, {$postcode}, {$country}'; $address = urlencode($address); If I view the source code when i load the page in the browser its obvious why the code is not working. See below. <iframe width="193px" height="160px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=+%24addressL1%2C+%24area%2C+%24county%2C+%24postcode&aq=0&ie=UTF8&hq=&hnear=+%24addressL1%2C+%24area%2C+%24county%2C+%24postcode&t=m&ll=,&z=12&iwloc= &output=embed"></iframe> As you can see the variable's are echoing wrong. Can someone please tell me how to write them within the string so they output their actual values. I know they have value as they are also echod on the page else where. Thanks Danny Quote Link to comment https://forums.phpfreaks.com/topic/258248-string-not-showing-correctly/ Share on other sites More sharing options...
S3cr3t Posted March 4, 2012 Share Posted March 4, 2012 <?php $address = $addressL1 .','. $area .','. $county .','. $postcode .','. $country; $address = urlencode($address); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258248-string-not-showing-correctly/#findComment-1323762 Share on other sites More sharing options...
scootstah Posted March 4, 2012 Share Posted March 4, 2012 You either need to concatenate the variables in the single quotes, $address = $addressL1 . ',' . $area . ',' . $county . ',' . $postcode . ',' . $country; Or use double quotes $address = "$addressL1, $area, $county, $postcode, $country"; Quote Link to comment https://forums.phpfreaks.com/topic/258248-string-not-showing-correctly/#findComment-1323765 Share on other sites More sharing options...
fife Posted March 4, 2012 Author Share Posted March 4, 2012 thanks matey that works perfectly!!!!!!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/258248-string-not-showing-correctly/#findComment-1323766 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.