I have a string, that is like the following:
$string = "New video gameSome TV showAnother item";
I want to be able to access each item individually, to get something like the following output:
New video game
Some TV show
Another item
How can I add a \n after each item name in the string or some other random character, that I can later explode into an array to access each item individually in the string?
$string = preg_replace('/([a-z])([A-Z])/', "\\1\n\\2", $string);
To answer your comment to include words that end in a closing parenthesis or a number:
$string = preg_replace('/([a-z0-9\)])([A-Z])/', "\\1\n\\2", $string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With