Regular Expressions and "\n"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Olate
    Member
    • Jan 2004
    • 61
    • 3.0.0 Release Candidate 3

    Regular Expressions and "\n"

    In a templating system I'm working on, I have a block which I would like to setup like this:

    PHP Code:
    {block:time}
    the time is {$time}
    {/
    block
    with each one on a new line. However I can't get that to work. I have to do:

    PHP Code:
    {block:time}The time is: {$time}
    {/
    block
    This appears to be because it doesnt like \n's before the .+ The regular expressions I'm using to parse this are:

    PHP Code:
    preg_match_all('/{block:'.$name.'}(\n*.+\n*){\/block}/m'$this->template$blocks); 
    and also

    PHP Code:
    $template preg_replace('/{block:'.$block.'}\\n*.+\\n*{\/block}/m',
    $this->blocks["$block"], $template); 
    Any suggestions on how to do what I want to do?
  • Stadler
    Senior Member
    • Oct 2001
    • 1021
    • 4.2.X

    #2
    Can't work, since you're using the m (PCRE_MULTILINE) modifier, so every line would count as a single line. See http://de.php.net/manual/en/pcre.pattern.modifiers.php for more info.
    Hints & Tips:
    [[vB3] More Spiders / Indexers / Archives for vB3 - list]|[List of one-time-emails to ban]


    http://sfx-images.mozilla.org/affili...efox_80x15.png

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...