I want to split the string from square brackets without removing any character. I tried the below code but it's not working for me.
$value = "<p> Lorem ipsum dolor [State] sit amet, consectetur [City] adipisicing [TopJob7] elit, sed do eiusmod [JobType]</p>";
$tagsReplace = preg_split('/[\[]*[\][]/U', $value, -1);
echo '<pre>';
print_r( $tagsReplace );
exit;
When I run the above code I got the output like
Array
(
[0] => <p> Lorem ipsum dolor
[1] => State
[2] => sit amet, consectetur
[3] => City
[4] => adipisicing
[5] => TopJob7
[6] => elit, sed do eiusmod
[7] => JobType
[8] => </p>
)
I want output like below.
Array
(
[0] => <p> Lorem ipsum dolor
[1] => [State]
[2] => sit amet, consectetur
[3] => [City]
[4] => adipisicing
[5] => [TopJob7]
[6] => elit, sed do eiusmod
[7] => [JobType]
[8] => </p>
)
Please help me where I did a mistake.