Here is a design though: For example is I put a link such as
http://example.com
in textarea. How do I get PHP t
I know this answer has been accepted and that this question is quite old, but it can be useful for other people looking for other implementations.
This is a modified version of the code posted by: Angel.King.47 on July 27,09:
$text = preg_replace(
array(
'/(^|\s|>)(www.[^<> \n\r]+)/iex',
'/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/iex',
'/(?(?=]*>.+<\/a>)(?:]*>.+<\/a>)|([^="\']?)((?:https?):\/\/([^<> \n\r]+)))/iex'
),
array(
"stripslashes((strlen('\\2')>0?'\\1\\2 \\3':'\\0'))",
"stripslashes((strlen('\\2')>0?'\\1\\2 \\4':'\\0'))",
"stripslashes((strlen('\\2')>0?'\\1\\3 ':'\\0'))",
),
$text
);
Changes:
As "Søren Løvborg" has stated, this function does not escape the URLs. I tried his/her class but it just didn't work as I expected (If you don't trust your users, then try his/her code first).