This article mainly introduces the method that PHP uses Preg_split and explode partition textarea to store content, and analyzes the functions of preg_split and explode functions, the use of techniques and the related considerations in the text string segmentation process with the example form. A friend you need can refer to the following
Today, there is an urgent bug, that is the background after configuring the whitelist, the mobile app is not valid, still display content. Received the message, then went through the process, found that the background configuration whitelist is configured in the textarea, one line, and then in the code to see, using the Explode function segmentation, where the delimiter is \ r \ n, the code is roughly as follows
Explode (' \ r \ n ', $val);
Then I tested it on my own development machine and found that it didn't split the contents of textarea into the database, so I found a useful function in the manual preg_split
$str = ' 12345 ';p rint_r (Preg_split ("/\n/", $str)),/*array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5) */
"Update"
In the afternoon by colleagues reminded, found that the original is a problem, because in Chrome and Firefox browser TextArea is a line break with \ n, and in IE is \ r \ n line break, so use str_replace replaced the next
$str = ' 12345 ';p rint_r (Explode ("\ n", Str_replace ("\ r \ n", "\ n", $str))); Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5)
Related recommendations:
PHP explode function Introduction and how to use a detailed explanation
2017 php explode function definition and Usage summary
PHP Split () string segmentation function Application Example