Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorverb
    • CommentTimeMar 25th 2007 edited
     permalink
    Hey,

    I'm trying to make a regular expression (PHP) that replaces something like {{Subpages(2, 3, ASC)}} with <? Subpages(2, 3, ASC); ?>. Thought it would be easy to do this, but I can't get it to work...
    {{Subpages(number, number, ASC or DESC)}} to <? Subpages($1, $2, $3); ?>, only then in a way preg_replace can handle it... :)

    Maybe someone (with a bit more knowledge of regular expressions than me) can help me out?
    • CommentAuthoreplawless
    • CommentTimeMar 25th 2007
     permalink
    <?php
    $yourstring = "{{TEST}}";
    $yourstring = preg_replace("/}}/","; ?".">",preg_replace("/{{/","<?php ",$yourstring));
    ?>

    Maybe there's a better way; who knows? Not me.
    • CommentAuthorverb
    • CommentTimeMar 26th 2007 edited
     permalink
    The string is not just {{TEST}}

    The string could be (example):
    <div id="subpages4">
    <h2>Subpages of page#4</h2>
    {{Subpages(4, 20, DESC)}}
    </div>


    {{Subpages(4, 20, DESC)}} is a 'template tag', which will generate a list of 'subpages'. (The first number is the ID of the page I want to display the subpages of, the second number is the maximum amount of subpages that will be displayed, and ASC/DESC will order them by date/time.)

    So, I need to convert this 'template tag' to <? Subpages(4, 20, DESC); ?> so the PHP function 'Subpages' will be executed.

    I hope I'm making any sense here :-P
    • CommentAuthoreplawless
    • CommentTimeMar 26th 2007
     permalink
    that is exactly what the code snippet I posted does...
    • CommentAuthorverb
    • CommentTimeMar 26th 2007
     permalink
    Not exactly. Well, it does, but it simply converts {{ to <? and }} to ; ?>
    So if someone types {{blahblah}} in his template... it will get converted to <? blahblah; ?>

    I has to be in a way it only converts the template tags I defined manually, not just everything between {{ and }}
    • CommentAuthorverb
    • CommentTimeMar 28th 2007 edited
     permalink
    Okay I *finally* have it working now, this is what I've got:
    $Body = preg_replace("/\{\{Subpages\((\d+), (\d+), (ASC|DESC)\)\}\}/i", "<? Subpages($1, $2, $3); ?>", $Body);
Add your comments
    Username Password
  • Format comments as (Help)