tags:

views:

54

answers:

4

Hi, i reposted this question because i didn't find a good answer.

i have a string which can contains text with urls.

i want a function to strip all urls from this string and just let the text.

by example the string can contains like this :

1) hey take a look here : http://xxx.xxx/545df5 this is nice!

2) hey take a look here : http://www.xxx.xxx/545df5 this is nice!

3) hey take a look here : xxx.xxx/545df5 this is nice!

4) hey take a look here : www.xxx.xxx/545df5 this is nice!

Thanks

A: 

Regular expression for URL and how to use regular expression with php should help you.

Shoban
A: 

What you really need is a solid regex to find urls in a string and you can preg_replace that pattern with nothing. I can tell you though that tracking down a regex like that is not easy. Depending on the variations in the urls you're looking for (i.e. http:// vs https:// vs ftp://) You could run into real trouble trying to account for all that.

Here is a page that I found to be a good start though.

Jage
A: 
$text = str_replace("http://", "", $text)
CheeseConQueso
A: 

Regex is the way to go as was discussed prior. Finding one isn't that terribly hard (google: url regex pattern) One example returned is here

http://www.geekzilla.co.uk/View2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm

I would also recommend you test your regex using one of the many fine online regex testers. My favorite (for non-java) is

http://www.regextester.com/

Bill