PDA

View Full Version : str_replace woes


Nightfire
12-30-2002, 05:30 PM
Can anyone figure out how to do this?
I'm trying to change urlhere to <a href="urlhere" target="_blank">urlhere[/link], but I can't figure out how to do it. Here's what I'm doing at the mo..

$row[3] = 'Ello me \'earties, here\'s a link for you urlhere';

$row[3] = str_replace('','<a href="'.$row[3].'" target="_blank">',$row[3]);
$row[3] = str_replace('','</a>',$row[3]);

As you can see, it's just adding the whole contents of $row[3] into the url, but it's showing urlhere for the name of the link. I can't figure it out.

Anyone got any ideas?

Nightfire
12-30-2002, 05:44 PM
Actually, nevermind. I'll just pinch it from phpBB or VB, which ever is easier for me to find it on

mordred
12-30-2002, 05:52 PM
Try this:


$row = "Ello me 'earties, here's a link for you http://www.xyz.com";
$row = preg_replace(
'/\\[link\\](.+?)\\[\\/link\\]/',
'<a href="\\\\1" target="_blank">\\\\1</a>',
$row
);

echo $row;

Nightfire
12-30-2002, 06:00 PM
Ta :) That's much better than the code in phpBB and much shorter