I am using preg_replace in PHP. When i use this code line:
echo nl2br(preg_replace("(http://.+) ", "<a href='$1'>[link]</a>", $row['description']));
It echoes "<a href=''>[link]</a>".
Here is the "description": http://www.youtube.com/watch?v=JDrnz8ZZtUE
What is wrong with this? (I also included the space in the description)
That's because you didn't specify delimiters. PHP will assume the ()
to be delimiters, thus eliminating your capture group.
"~(http://.+)~"
You don't have any delimiter. Here is the syntax :
$pattern = '/(\w+) (\d+), (\d+)/i';
Try to do like this :
echo nl2br(preg_replace("/(http://.+)/", "<a href='$1'>[link]</a>", $row['description']));