AbraCadaver给了我一个指向phpsandbox的链接。以下代码适用于http://sandbox.onlinephpfunctions.com/。
为什么它在我的电脑中不起作用?我有wampstack-5.6.20-0,php版本5.6.20并在Opera,Firefox,Explorer和Chrome上查看oce。
我有一个字符串,我想分割成碎片以便用胶水串连接它们或者preg_replace split_substring(aaaa)和glue_string(jsonString):
$tmpStr = '<br><div id="10"><p>Displaying 1-5 of 11 results. <br> <span class="disabled">«</span> <span class="disabled">‹</span> Page 1 of 3 pages<a href="?page=2&formData=aaaa" title="Next page">›</a> <a href="?page=3&formData=aaaa" title="Last page">»</a><br>All pages: <a href="?page=1&formData=aaaa">1</a> <a href="?page=2&formData=aaaa">2</a> <a href="?page=3&formData=aaaa">3</a> </p></div><br> ';
$tmpArr = explode("aaaa", $tmpStr);
print_r("<br> 94 EventSearchCOntroller tmpArr =<pre>"); print_r($tmpArr);
结果是:
Array
(
[0] =>
107 PaginatorTrait pagHTML =
Displaying 1-5 of 11 results.
« ‹ Page 1 of 3 pages› »
All pages: 1 2 3
)
$tmpStr2=preg_replace( "/aaaa/", "jsonString", $tmpStr );
$tmpStr2=preg_replace( "/aaaa/", "jsonString", $tmpStr, 100 );
print_r( "<br> 97 EventSearchCOntroller tmpStr2 =".$tmpStr2 );
//Result is in both cases (using 100 limit, and without a limit):
97 EventSearchCOntroller tmpStr2 =
如果我打印结果,则不会拆分字符串。原因在哪里?
答案 0 :(得分:0)
试试这个,看看输出:
$tmpStr = '<br><div id="10"><p>Displaying 1-5 of 11 results. <br> <span class="disabled">«</span> <span class="disabled">‹</span> Page 1 of 3 pages<a href="?page=2&formData=aaaa" title="Next page">›</a> <a href="?page=3&formData=aaaa" title="Last page">»</a><br>All pages: <a href="?page=1&formData=aaaa">1</a> <a href="?page=2&formData=aaaa">2</a> <a href="?page=3&formData=aaaa">3</a> </p></div><br> ';
$tmpArr = explode("aaaa", $tmpStr);
echo "<textarea rows='20' cols='120'>";
print_r($tmpArr);
echo "</textarea>";