headmine Posted July 1, 2010 Share Posted July 1, 2010 I have a string of Data. Inside this string there is a line of text that says Where: 1234 Main Street. What I would like to do is grab the address that comes after "Where:" and have the output with a link to google maps ex Where: <a href="http://maps.google.com?q=1234+Main+Street">1234 Main Street</a> Would I use preg_replace for this? Or am I attacking this the wrong way? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 1, 2010 Share Posted July 1, 2010 $str = preg_replace('/Where: ([^\n]*)/m','Where: <a href="http://maps.google.com?q=$1">$1</a>', $str ); that will leave spaces in the url. IF you need the + in there then: preg_match('/Where: ([^\n]*)/m', $str , $matches ); $term = str_replace(' ', '+', $matches[1]); $str = preg_replace('/Where: ([^\n]*)/m','Where: <a href="http://maps.google.com?q='.$term.'">$1</a>', $str ); Quote Link to comment Share on other sites More sharing options...
headmine Posted July 1, 2010 Author Share Posted July 1, 2010 Exactly what I needed. I knew about spaces and a str_replace is exactly what I was going to do. Thanks so much for your help. Quote Link to comment 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.