Search code examples
phparrayssplit

Split a string by <br> tags wrapped in newlines


We have rows:

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

For explode in array we test next:

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

But it not worked.

Tell me please how to split a string into array elements ?


Solution

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

    Two things:

    1. You have to split by a new line followed by a <br> followed by a new line
    2. Escape characters only work in double quotes, not single ones.