我想通過查找PHP標籤來拆分帶換行符的字符串。需要通過查找PHP標籤來拆分帶換行符的字符串
這裏是我的代碼,我到目前爲止有:
$contents = '
some test
some more test
test 1
<?php
test 2 and test 4
test 6
?>
test 7
test 9
<?php
test 10
test 12
>?
test 13
<?php test 14
test 16
?>
test 17
';
正如你所知道的,PHP代碼是偶的測試實例,和ODD測試的例子是PHP標籤外面。
我所希望做的是提取到一個數組的PHP代碼每次迭代:
預期結果:
array(
[0] => <?php
test 2 and test 4
test 6
?>
[1] => <?php
test 10
test 12
>?
[2] => <?php test 14
test 16
?>
)
我試圖與preg_split
由結束標記,然後通過捕獲$explode[1]
期初標籤,但我的代碼是錯誤的...
$ends = preg_split("/[?>]/s", $contents, PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE);
print_r($ends);
foreach($ends as $flufcode){
$trimcode = explode('<?php', $flufcode);
echo $trimcode . " next:";
}
到目前爲止,我preg_split
不工作,我相信我的[R斷行後egex不掃描。
In line「test 12>?」你有一個synatx錯誤。它必須是 「測試12?」「我認爲 – Kingalione 2013-04-05 01:16:57