tags:

views:

34

answers:

2

Hello,

i have a variable in php can be like this : $string = "hello check out this http://xx.xx/xxx & thanks !!";

i want a function to strip that link and remove it from the string, the url can be with WWW. or without it.

also, this variable can contains multiple urls .

Thanks

A: 

You could use regular expressions to do it:

$string = preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '', $string);

That will find every instance of a URL in the string and replace it with a blank string.

Parrots
A: 

You can use a regular expression to match and replace all URL formats, as follows:

$string = preg_replace("/(^¦\s)(http:\/\/)?(www\.)?[\.0-9a-zA-Z\-_~]+\.(com¦net¦org¦info¦name¦biz¦.+\.\w\w)((\/)?[0-9a-zA-Z\.\-_~#]+)?\b/ie","",$string);
Dustin Fineout