3

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.

1
  • Please show an input example. Commented Nov 28, 2012 at 10:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

That doesn't work Parse error: syntax error, unexpected '(' in /home/gamingon/public_html/prxa.info/xenforo_convert.php on line 65
@LiamDawe See updated answer. So, there must be an error somewhere else.
Will that work when there are more than one? Maybe that's my issue.
@LiamDawe Try it yourself. Append another [url] at $message. It will be changed as well.
I ask as it doesn't work for me and i was thinking that was the issue.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.