0

I am working on a taggable report system where a textblock will store information like this:

This is a line with a {TAG} . The {TAG} will be replaced with normal text via str_replace.
{if 1==1}
    I would like to be able to do if statements like this.
{/if}

So the {TAG} gets replaced easy enough, but is there a way to parse a text block to handle if/else statements?

spyke01
  • 435
  • 3
  • 15
  • Yes, possible. Various templating engines implement that (usually by converting those placeholders into a php script). Use one of those as it's complex to code on your own. – mario Nov 09 '12 at 01:04

1 Answers1

1

In just pure php, if you're using heredoc syntax, you won't be able to do if blocks inside strings.

If you're okay with concatenating strings, you can use the ternary operator like this :

$myString =
    "This is a line with a {TAG}. " .
    "The {TAG} will be replaced with normal text via str_replace. " .
    ( 1==1 ? "I would like to be able to do if statements like this." : "" ) . " "
;

Hope that helps.

tazer84
  • 1,743
  • 12
  • 11