php,爆炸无效,php preg_replace无效

时间:2016-12-12 13:50:14

标签: php preg-replace explode

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">&laquo;</span> <span class="disabled">&lsaquo;</span> Page 1 of 3 pages<a href="?page=2&amp;formData=aaaa" title="Next page">&rsaquo;</a> <a href="?page=3&amp;formData=aaaa" title="Last page">&raquo;</a><br>All pages: <a href="?page=1&amp;formData=aaaa">1</a> <a href="?page=2&amp;formData=aaaa">2</a> <a href="?page=3&amp;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 =

如果我打印结果,则不会拆分字符串。原因在哪里?

1 个答案:

答案 0 :(得分:0)

试试这个,看看输出:

$tmpStr = '<br><div id="10"><p>Displaying 1-5 of 11 results. <br> <span class="disabled">&laquo;</span> <span class="disabled">&lsaquo;</span> Page 1 of 3 pages<a href="?page=2&amp;formData=aaaa" title="Next page">&rsaquo;</a> <a href="?page=3&amp;formData=aaaa" title="Last page">&raquo;</a><br>All pages: <a href="?page=1&amp;formData=aaaa">1</a> <a href="?page=2&amp;formData=aaaa">2</a> <a href="?page=3&amp;formData=aaaa">3</a>  </p></div><br> ';

$tmpArr = explode("aaaa", $tmpStr);
echo "<textarea rows='20' cols='120'>";
print_r($tmpArr);
echo "</textarea>";