Hi All, Generic article greeting input here!
Replace Characters with this Easy PHP Script
I recently decided that with some enquiry forms that I wanted to send out a link to Google maps so that the person who recieves the enquiry can locate them on the map easily. I didn’t want the hassle of setting up a SOAP service or anything like that, so this just manipulates a URL query. One thing I needed to do was to replace spaces with a ‘+’ character, so it would work properly.
Here’s the script!
<?php $address = "120 Purple Nipple Lane"; $postcode = "ME9 8CP"; // this is a made up address, so suggest getting a working one $map = "http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q=" . $address . ",+ " . $postcode . "&sll=53.800651,-4.064941&sspn=19.773582,57.128906&ie=UTF8&t=h&z=16&g=" . $address . ",+ " . $postcode . "&iwloc=addr"; $maplink = str_replace(" ","+",$map); // remove the space and replace with a plus ?> <a href="<?php echo $maplink; ?>">Click for map!</a>
Ok thats it! Enjoy, you can send it out with an email if you like, or whatever, it’s handy though, note you don’t need a full address, postcode and first line is adequate.




Recent Comments