Reputation: 389
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)
Upvotes: 0
Views: 54
Reputation: 174957
That's because you didn't specify delimiters. PHP will assume the ()
to be delimiters, thus eliminating your capture group.
"~(http://.+)~"
Upvotes: 4
Reputation: 1576
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']));
Upvotes: 0