NaughtySquid
NaughtySquid

Reputation: 2097

replace this bbcode with this bbcode

Basically I am trying to convert xenforo's forum script database over to my custom one (dropping my use on xenforo) and their bbcode is annoying me.

I am trying to change all the url bbcode from theirs to mine with this:

$message = preg_replace("/\[url\=\'(.+?)\'\](.+?)\[\/url\]/is",
                        "[url=$1]$2[/url]", $message);

Basically they have single quotes surrounding the urls i don't want them but my code doesn't work.

Upvotes: 3

Views: 286

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74048

If you use double quotes for your regexp string, you must double escape, because PHP interprets backslashes as well

$message = preg_replace("/\\[url='(.+?)'\\](.+?)\\[\\/url\\]/is",
                        "[url=$1]$2[/url]", $message);

Test case

<?php
$message = "[url='http://www.example.com/test']My test URL[/url]";
$message = preg_replace("/\\[url='(.+?)'\\](.+?)\\[\\/url\\]/is",
                        "[url=$1]$2[/url]", $message);
echo "$message\n";

and its output

[url=http://www.example.com/test]My test URL[/url]

The test is done on Ubuntu 12.04 and with PHP 5.3.10.

Upvotes: 1

Related Questions