0

「Smartyforeach」のコンポートを再現したいと思います。

tplファイルの内容は($ tplContent)です:

{foreach from=$tabMethodTest item=entry}
    /**
     * @todo Implement test{$entry.name}().
     */
    public function test{$entry.name}() {
        $this->markTestIncomplete("This test has not been implemented yet.");
    }
{/foreach}

preg_match_allコードは次のとおりです。

preg_match_all("/(.*)\{foreach(.*)\}(.*)\{\/foreach\}(.*)/im",$tplContent,$regsTplResult);
print_r($regsTplResult);

print_r return:

Array
(
    [0] => Array
        (
        )

    [1] => Array
        (
        )

    [2] => Array
        (
        )

    [3] => Array
        (
        )

    [4] => Array
        (
        )

)

{foreach} {/ foreach}の間にコードを返すにはどうすればよいですか?

4

2 に答える 2

0

あなたが何をしているのかまったくわかりませんが、これはうまくいくようです:

$tplContent = "{foreach from=\$tabMethodTest item=entry}\nHello\n{/foreach}";
$pattern = '/\{foreach from=\$tabMethodTest item=entry\}[\r\n]{1,2}(.*)[\r\n]{1,2}\{\/foreach\}/im';
preg_match_all($pattern,$tplContent,$regsTplResult);
print_r($regsTplResult);
于 2009-04-02T18:59:18.410 に答える