how do that in str_replace

I have a guestbook, and I want to convert site address in the following [link]www.yahoo.com[/link] to <a>...

So how is it do that str_replace?

Answers


str_replace is not powerful enough to do this. You can use preg_replace:

$res = preg_replace('#\\[link\\](?![^:]+script:)([^:<"\\[]+:)?([^<"\\[]+)\\[/link\\]#e',
                    "'<a href=\"'.('\\1'?'\\1':'http://').'\\2\">click here</a>'",
                    $input);

Example: http://www.ideone.com/lTknX

But it's better to use a BBCode parser.


This should do that for you:

$string = "[link]www.yahoo.com[/link]";

echo preg_replace("/\[link\](.*)\[\/link\]/", "<a href='$1'>click here</a>", $string);

Need Your Help

Making multiple objects draggable

actionscript-3 actionscript actionscript-2

I have about 50 symbols that I want to make draggable. Nothing fancy, just the ability to click it and drag it to a different location.

How accurate is Maxminds GeoIP2 compared to GeoLite2 at the first tuesday of the month exactly?

geoip maxmind

I would like to know how much the database GeoIP2 is more accurate then the GeoLite2 database, when both databases are downloaded at the first tuesday of the month.