P粉4209586922023-08-07 13:34:48
I have been using this with great success:
$array = preg_split("/\r\n|\n|\r/", $string);
With the last \r, thanks @LobsterMan):
P粉3919557632023-08-07 00:15:31
You can use the explode function and use "\n" as the separator:
$your_array = explode("\n", $your_string_from_db);
For example, if you have the following code snippet:
$str = "My text1\nMy text2\nMy text3"; $arr = explode("\n", $str); var_dump($arr);
You will get the following output:
array 0 => string 'My text1' (length=8) 1 => string 'My text2' (length=8) 2 => string 'My text3' (length=8)
Note that you have to use a Note that you must use a double-quoted string so that \n will be interpreted as a newline character. (See the man page for more details.)