2

I'm making a website and a PHPBB3 forum. I want the messages that are posted on the forum to show up on the main page of the website. I have gotten this concept down, except that the bbcode parsing is weird (phpbb3 adds a UID after each bbcode tag) and my bbcode parser does not include this. Since the UID is different for each post, I'm trying to get the PHP code to parse and remove this via MYSQL.

$query = @mysql_query("SELECT * FROM phpbb_posts where forum_id = 2;") or die (mysql_error());
$uid = $row['bbcode_uid'];
$content = $row['post_text'];
$content = str_replace($uid, '', $content); 
$content = BBCode2html($content);
echo $content;

Is there a way I could replace the UID (bbcode looks like [u:1h77z1wc]UNDERLINED[/u:1h77z1wc] instead of [u]UNDERLINED[/u])?

2 Answers 2

3

You could replace it with a regex...

preg_replace('/\[((\w+)(:\w+))](.*?)\[\/\1]/s', '[$2]$4[/$2]', $str);
Sign up to request clarification or add additional context in comments.

Comments

0

The following regular expression should do the trick:

preg_replace( '/\[(\/?[^:]+):[^\]]+\]/', '[$1]', $str );

Comments

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.