Jump to content

Mini parsing script


astropirit

Recommended Posts

Greetings all

i am trying to write a templating engine and i require a simple conditional statement to be part of it.

the syntax for the statement would go something like this:

{-IF UserOnline DO 'this will be printed out! and this {-UserName-}' ''-}

 

what i would like to do is find a statement such as that and get the argument in this case "UserOnline" and if it returns true then it will replace the while thing  with what is inside the single quotes ''.

i just need help with the ragex part. i dont know how i would test if there is another "{-" inside it should look for two "-}" before ending the search.

so far i have this but it definatly isnt working

 

$prepat = '([A-Za-z0-9(\<(/?[^\>]+)\>)(\{\-([A-Za-z0-9-]+)\-\})-]+)';
$pattern = '`' .$this->LEFT_DELIMITER ."\s*" ."IF" ."\s*" ."UserOnline"."\s*" ."DO" ."\s*'\s*" .$prepat ."\s*'\s*" .$this->RIGHT_DELIMITER .'`i';
        

 

any help would be greatly apreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.