Jump to content

Big url to readable url


The Little Guy

Recommended Posts

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)?

Link to comment
https://forums.phpfreaks.com/topic/222115-big-url-to-readable-url/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.