Hi,

Ive written a regular expression for my template system. Its for a simple IF statement.

$this->html = preg_replace_callback('/\[IF: (.+?)\](.+?)\[\/IF\]/i', array(&$this, 'doIF'), $this->html);

this works fine if the html is all on one line... eg...

[IF: err:eq:1]<h2>The username &frasl; password entered was incorrect.</h2>[/IF]

but if it is...

[IF: isSuperAdmin:eq:1]
	<div id="info">
    <form method="post">
    Add a new username &nbsp;<input value="Sample User" type="text" name="vUsername">
    <input type="submit" name="frmAddUser" value="Create">
    </form>
    </div>
    <h2>Users</h2>
[/IF]

it doesnt work...

any ideas?

    You've got to add s to your pattern modifiers if you want it to read over multiple lines - try

    '/[IF: (.+?)](.+?)[\/IF]/is'

      Specifically, you need the "s" modifier if you want the "." wildcard character to include newlines.

        Write a Reply...