Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the obvious <em>easy</em> answer is to present your "summary" without any bbcode-driven markup at all (regex below taken from <a href="http://twelvestone.com/forum_thread/view/28916" rel="nofollow noreferrer">here</a>)</p> <pre><code>$summary = substr( preg_replace( '|[[\/\!]*?[^\[\]]*?]|si', '', $article ), 0, 200 ); </code></pre> <p>However, do do the job you explicitly describe is going to require more than just a regex. A lexer/parser would do the trick, but that's a moderately complicated topic. I'll see if I can come up w/something.</p> <h2>EDIT</h2> <p>Here's a pretty ghetto version of a lexer, but for this example it works. This converts an input string into bbcode tokens.</p> <pre><code>&lt;?php class SimpleBBCodeLexer { protected $tokens = array() , $patterns = array( self::TOKEN_OPEN_TAG =&gt; "/\\[[a-z].*?\\]/" , self::TOKEN_CLOSE_TAG =&gt; "/\\[\\/[a-z].*?\\]/" ); const TOKEN_TEXT = 'TEXT'; const TOKEN_OPEN_TAG = 'OPEN_TAG'; const TOKEN_CLOSE_TAG = 'CLOSE_TAG'; public function __construct( $input ) { for ( $i = 0, $l = strlen( $input ); $i &lt; $l; $i++ ) { $this-&gt;processChar( $input{$i} ); } $this-&gt;processChar(); } protected function processChar( $char=null ) { static $tokenFragment = ''; $tokenFragment = $this-&gt;processTokenFragment( $tokenFragment ); if ( is_null( $char ) ) { $this-&gt;addToken( $tokenFragment ); } else { $tokenFragment .= $char; } } protected function processTokenFragment( $tokenFragment ) { foreach ( $this-&gt;patterns as $type =&gt; $pattern ) { if ( preg_match( $pattern, $tokenFragment, $matches ) ) { if ( $matches[0] != $tokenFragment ) { $this-&gt;addToken( substr( $tokenFragment, 0, -( strlen( $matches[0] ) ) ) ); } $this-&gt;addToken( $matches[0], $type ); return ''; } } return $tokenFragment; } protected function addToken( $token, $type=self::TOKEN_TEXT ) { $this-&gt;tokens[] = array( $type =&gt; $token ); } public function getTokens() { return $this-&gt;tokens; } } $l = new SimpleBBCodeLexer( 'some [b]sample[/b] bbcode that [i] should [url="http://www.google.com"]support[/url] what [/i] you need.' ); echo '&lt;pre&gt;'; print_r( $l-&gt;getTokens() ); echo '&lt;/pre&gt;'; </code></pre> <p>The next step would be to create a parser that loops over these tokens and takes action as it encounters each type. Maybe I'll have time to make it later...</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.
    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