Has anybody written a function to replace ALL URLs in a given string?
Suppose I've got
$text="Link a: http://www.link.com and here is link b: http://www.anotherlink.com. Go there for more info";
I now want to replace ALL URLs in this string and as a result get anything like this (e.g.):
$text="Link a: and here is link b: . Go there for more info";
Any idea?
there's a post in the manual under [man]ereg_replace[/man] that can be adapted
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "", $text);
this will strip all urls in the text
PERFECT! Thanks! Could you do me a favour and explain this reg expression???
Originally posted by weekender there's a post in the manual under [man]ereg_replace[/man] that can be adapted $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "", $text); this will strip all urls in the text [/B]
Originally posted by weekender there's a post in the manual under [man]ereg_replace[/man] that can be adapted
this will strip all urls in the text [/B]
sorry, i can't! i am no good with regex, and only know it because i've been looking for the same thing recently.
anyone else care to explain?
Originally posted by weekender $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "", $text); [/B]
Originally posted by weekender
[/B]
im not excellent with them either but i believe it is saying
[[:alpha:]] is for the http https ftp etc.. then u need the :// next you cannot have < > or a space then u need a combination(or one or the other) of alpha numeric numbers..
If I use the line you submitted exactly as printed here, I get a
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in