我試圖保持preg_split分隔符(< tr>和</tr>),而不將它分開放置在新的數組位置,並且無法弄清楚。所以任何幫助將不勝感激。Preg_split,如何保持分隔符?
我試圖採取從下一個HTML代碼中的每一行,並把它放在一個不同的排列位置:
<tr><td> one column </td><td>second column</td></tr><tr><td> one column </td><td>second column</td></tr>
下面是我有:
array_unique(preg_split('[<tr[^>]*>(.*?)</tr>]',$table,NULL,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
如果我這樣做我的陣列的這個的var_dump代碼顯示:
array(2) {
[0]=>
string(43) "<td> one column </td><td>second column</td>"
[1]=>
string(43) "<td> one column </td><td>second column</td>"
}
而我想要的是:
array(2) {
[0]=>
string(52) "<tr><td> one column </td><td>second column</td></tr>"
[1]=>
string(52) "<tr><td> one column </td><td>second column</td></tr>"
}
事先,非常感謝您的幫助和時間。
太棒了,像魅力一樣工作。你搖滾的人! 非常感謝! – user3321425 2015-03-02 09:22:20