The Little Guy Posted December 19, 2010 Share Posted December 19, 2010 I have this piece of code: if(preg_match("~(http://(.+?))(.\h)~", $list, $matches)){ $m = parse_url($matches[1]); $host = trim(strtolower($m['host']), 'www.'); $list = preg_replace("~http://(.+?)(.\h)~", '<a href="'.$matches[1].'">'.$host.'</a>$2', $list); } It takes a url and converts to a nice readable url. for example, if I use this url: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=cat it will convert it to this: google.com The problem is, that it doesn't convert urls if they are at the end of a line. What would the best way be to match ALL urls (know matter where they are in the context) and allow me to make them more readable (like the way I have now)? 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.