0

私は、テキストブロックが次のような情報を保存するタグ付け可能なレポートシステムに取り組んでいます:

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}

{TAG} は簡単に置き換えられますが、テキスト ブロックを解析して if/else ステートメントを処理する方法はありますか?

4

1 に答える 1

1

純粋な php では、ヒアドキュメント構文を使用している場合、文字列内のブロックを if することはできません。

文字列を連結しても問題ない場合は、次のように三項演算子を使用できます。

$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." : "" ) . " "
;

それが役立つことを願っています。

于 2012-11-09T02:04:11.383 に答える