php如何将字符串拆分为数组元素?

时间:2014-07-22 01:54:00

标签: php arrays

我们有行:

1 test1
<br> 
2 test2
<br> 
3 test3
<br> 
4 test4

对于数组中的爆炸,我们接下来测试:

$ArrText = explode("\n",$text);
$ArrText = explode("<br>",$text);

但它无效。

请告诉我如何将字符串拆分为数组元素?

1 个答案:

答案 0 :(得分:5)

$ArrText = explode("\n<br>\n",$text);

两件事:

  1. 您必须按新行分隔后跟<br>后跟新行
  2. Escape characters only work in double quotes, not single ones