Split <b> in php

For this code, I need to take a line like

<b>hey</b> more text<b>hey2</b> other text


and I expect the returned array to look like

<b>hey</b> more text
<b>hey2</b> other text


However, it is not. How to make it look like above? my test code

$myArr = split("<b>", "<b>hey</b> more text<b>hey2</b> other text");
foreach($myArr as $e)
    echo "e = $e\n-------------\n";



e =
e = hey</b> more text
e = hey2</b> other text


I need b> to stay. How do I remove the first empty array?


source to share

4 answers

the "split" function is deprecated, it is best not to use it.

Instead, use "explode" on the <b> and then add back to each element and pop the first element out of the array.



echo "e = <b>$e\n-------------\n";


You need to add <b> because split removes it from the string.

As for empty elements of the try array:

$array = array_filter($array); 




you can use it as it is and add $ e = "". $ e; before the echo



You can add <b>

after splitting and just the pop()

first variable in the array.



All Articles