How to explode a string, with spaces and new lines?
delimiter, php
Solution
You could just do a
$segments = preg_split('/[\s]+/', $string);
This function will split `$string` at every whitespace (`\s`) occurrence, including spaces, tabs and newlines. Multiple sequential white spaces will count as one (e.g. `"hello, \n\t \n\nworld!"` will be split in `hello,` and `world!` only, without empty strings in the middle.
See function reference here.
Problem
I would like to explode a string (separated based on a delimiter and placed into an array), using both a space (" ") and a newline ("\n") as a delimiter. The method (which I don't think is the best way) is to: - Explode the array by spaces - Remake the string from the array - Explode it again for new lines - MySQL escape the individual elements. Question: How do I exploded a string by both a space and new line? Reference to: new line Array