Need help. How to split string to array using tags ?
input:
<aa> test1 </aa> test2 <aa> test3 </aa> test4 ....
output:
arr[0] = <aa> test1 </aa>;
arr[1] = test2;
arr[2] = <aa> test3 </aa>;
arr[3] = test4;
Thanks in advance!
Need help. How to split string to array using tags ?
input:
<aa> test1 </aa> test2 <aa> test3 </aa> test4 ....
output:
arr[0] = <aa> test1 </aa>;
arr[1] = test2;
arr[2] = <aa> test3 </aa>;
arr[3] = test4;
Thanks in advance!
Using the super-awesome power of semi-dodgy regex!
$string = "<aa> test1 </aa> test2 <aa> test3 </aa> test4";
$arr = preg_split('/(<[0-9a-zA-Z_]+>[^<]*<\/[0-9a-zA-Z_]+>)/', $string, NULL, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);