Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP method for replacing BBCode quotes
    primarykey
    data
    text
    <p>I need to replace BBCode quotes from a phpBB3 forum using PHP. Quoted posts look like this:</p> <pre><code>[quote=&amp;quot;John Doe&amp;quot;:2sxn61wz][quote=&amp;quot;Bob&amp;quot;:2sxn61wz]Some text from Bob[/quote:2sxn61wz]Some text from John Doe[/quote:2sxn61wz]Some more text </code></pre> <p>I would like to parse this string and end up with an array like:</p> <pre><code>Array ( [0] =&gt; Array ( [0] =&gt; 'John Doe' [1] =&gt; 'Some text from John Doe' ) [1] =&gt; Array ( [0] =&gt; 'Bob' [1] =&gt; 'Some text from Bob' ) ) </code></pre> <p>What would be the best approach to recursively find these quote blocks and their content? Thanks in advance for any help on that!</p> <p><strong>As suggested in the comments:</strong></p> <pre><code>$str = '[quote=&amp;quot;John Doe&amp;quot;:2sxn61wz][quote=&amp;quot;Bob&amp;quot;:2sxn61wz]Some text from Bob[/quote:2sxn61wz]Some text from John Doe[/quote:2sxn61wz]Some more text'; $uid = '2sxn61wz'; print_r(quoteParser($str, $uid)); function quoteParser($str, $uid) { $pattern = "#\[quote(?:=&amp;quot;(.*?)&amp;quot;)?:$uid\]((?!\[quote(?:=&amp;quot;.*?&amp;quot;)?:$uid\]).)?#ise"; echo "Unparsed string: " . $str . "&lt;br /&gt;&lt;br /&gt;"; echo "Pattern: " . $pattern . "&lt;br /&gt;&lt;br /&gt;"; preg_match_all($pattern, $str, $matches); return $matches; } </code></pre> <p><strong>Output:</strong></p> <pre><code>Array ( [0] =&gt; Array ( [0] =&gt; [quote="John Doe":2sxn61wz] [1] =&gt; [quote="Bob":2sxn61wz]S ) [1] =&gt; Array ( [0] =&gt; John Doe [1] =&gt; Bob ) [2] =&gt; Array ( [0] =&gt; [1] =&gt; S ) ) </code></pre> <p>That's quite what I need but I don't get the quoted text. Only the user names. Any help? Thanks so far.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload