Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Apparently what you're wanting is to turn your BBCode output into HTML. You can check the <a href="http://php.net/manual/en/function.bbcode-create.php" rel="nofollow"><strong><code>bbcode_create()</code></strong></a> function if you like. Otherwise a different recursion -to format your text- is a better option, I believe.</p> <pre><code>&lt;style type="text/css"&gt; body { font-size:.9em; font-family:Arial, Helvetica, sans-serif; } .post { margin:1em; padding:1em; font-size:1em; border:1px solid #999; } .post &gt; .text {margin:1em .4em} .post &gt; div:first-child {margin-top:0} .post &gt; div:last-child {margin-bottom:0} .post &gt; .quote {border-color:#CCC} .quote { margin:1em 2em; background-color:#F9F9F9; border:1px solid #AAA; font-style:italic; } .quote .text {margin:.7em 1em} .quote .author { color:#039; font-size:.8em; background-color:#E0E0E0; padding:.5em .8em; margin:.5em; } .author a { font-weight:bold; text-decoration:none; color:inherit; } .author a:hover {text-decoration:underline;} &lt;/style&gt; </code></pre> <hr /> <pre><code>function str2html($str,$className='post') { $patPost = '~( \[quote=&amp;quot;(?:(?!&amp;quot;).)+&amp;quot;:(\w+)(?:\]) (?: (?(?=\[quote=&amp;quot;(?:(?!&amp;quot;).+)&amp;quot;:\w+\]) (?R) | (?(?!\[/quote:\2\]).) )* ) \[/quote:\2\] )~xis'; // note that these 2 are not identical $patQuote = '~ (\[quote=&amp;quot;((?:(?!&amp;quot;).)+)&amp;quot;:(\w+)(?:\])) ( (?(?=\[quote=&amp;quot;(?:(?!&amp;quot;).+)&amp;quot;:\w+\]) (?R) | (?(?!\[/quote:\3\]).) )* ) (\[/quote:\3\]) ~xis'; $arr = preg_split($patPost,$str,-1,PREG_SPLIT_DELIM_CAPTURE); foreach ($arr as &amp;$value) $value = trim($value); unset($value); //echo '&lt;h2&gt;split post&lt;/h2&gt;'; print_r($arr); $res = empty($className) ? '' : "&lt;div class=\"{$className}\"&gt;"; for ($i = 0; $i &lt; count($arr); $i += 3) { if (!empty($arr[$i])) $res .= '&lt;div class="text"&gt;' . $arr[$i] . '&lt;/div&gt;'; if (!empty($arr[$i+1])) $res .= preg_replace_callback($patQuote,'replaceQuote',$arr[$i+1]); } $res .= empty($className) ? '' : '&lt;/div&gt;'; return $res; } function replaceQuote($m) { //echo '&lt;h2&gt;replacing quotes&lt;/h2&gt;'; print_r($m); $res = '&lt;div class="quote"&gt;'; $res .= '&lt;div class="author"&gt;'; $res .= '&lt;a href=""&gt;' . $m[2] . '&lt;/a&gt; wrote:'; $res .= '&lt;/div&gt;'; $res .= str2html($m[4],''); $res .= '&lt;/div&gt;'; return $res; } </code></pre> <p>You can call this by <code>echo str2html('some string here')</code>. You get the idea.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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