Jump to content

preg_replace bbcode [quote] issue


newbtophp

Recommended Posts

Ok I've coded a simple BBCode parser using regex. I got  the [ quote ] bbcode to work recursively so it can allow quote bbcode within each others, however I want to also support the following [ quote name=newbtophp ] bbcode, I used the same method as the [ quote ] but doesnt seem to work anyone can help  :(

 

function Quote($name='null',$text) {
$regex = '~\[quote\](.*)\[/quote\]~ise';
$regex2 = '~\[quote=(.*)\](.*)\[/quote\]~ise';
if($name != "null"){
$text = "<fieldset class=\"quote\"><legend>Quote - {$name}</legend>{$text}</fieldset>";
} else {
$text = "<fieldset class=\"quote\"><legend>Quote</legend>{$text}</fieldset>";
}
$text = preg_replace($regex, 'Quote(\'null\',\'$1\')', $text);
$text = preg_replace($regex2, 'Quote(\'$1\',\'$2\')', $text);
return $text;
}

function BBcode($Text){
      $Text = preg_replace('~\[quote\](.*)\[/quote\]~ise', 'Quote(\'null\',\'$1\')', $Text);
      
      $Text = preg_replace('~\[quote=(.*)\](.*)\[/quote\]~ise', 'Quote(\'$1\',\'$2\')', $Text);

return $Text;

}

 

Example scenario:

 

<?php
echo BBcode('[quote]
[quote name=testuser]
b
u
m
p[/quote]
[/quote]');
?>

Link to comment
https://forums.phpfreaks.com/topic/198220-preg_replace-bbcode-quote-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.