Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would first like to say, are you creating your own template library? There are some mature ones around like <a href="http://www.smarty.net/" rel="nofollow noreferrer">Smarty</a> which should be able to fill your requirements. This article by Jeff Atwood is also good read : "<a href="http://www.codinghorror.com/blog/archives/001145.html" rel="nofollow noreferrer">Don't Reinvent The Wheel, Unless You Plan on Learning More About Wheels</a>"</p> <p>If you want to roll your own solution then that is fine, here are some suggestions.</p> <h1>BBCode</h1> <hr> <p>This method relies on having the BBCode extension installed with PHP, it is native and does not rely on the regular expression engine (slow). This solution will <em>probably</em> be the fastest.</p> <p>You can have the BBCode parser convert </p> <pre><code>[LOOP]&lt;td&gt;&lt;?php print $row-&gt;title; ?&gt;&lt;/td&gt;[/LOOP] </code></pre> <p>into</p> <pre><code>&lt;?php foreach($result as $row): ?&gt;&lt;td&gt;&lt;?php print $row-&gt;title; ?&gt;&lt;/td&gt;&lt;?php endforeach; ?&gt; </code></pre> <p>Look into the BBCode arguments to learn about passing variables into your [LOOP] syntax.</p> <p>You can view some more examples on the <a href="http://uk.php.net/manual/en/function.bbcode-create.php" rel="nofollow noreferrer">bbcode_create</a> method page.</p> <h1><strong>Regular Expressions</strong></h1> <hr> <p>They are a little bit slower, but are enabled by default on all PHP installations. </p> <p>Credits to go Gumbo for this regular expression (You should up-vote him).</p> <pre><code>/\[LOOP]((?:[^[]+|\[(?=\/LOOP]))*)\[\/LOOP]/ </code></pre> <p>You can then use it as follows.</p> <pre><code>if (preg_match('%\[LOOP\]((?:[^[]+|\[(?=/LOOP\]))*)\[/LOOP\]%i', $subject, $result)) { # Successful match # You can access the content using $result[1]; } else { # Match attempt failed } </code></pre> <p>-Mathew</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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