Php string (text) filtering-regular expressions can be used to delete code of all invalid characters other than letters, numbers, and common punctuation marks. Cause: A piece of excel file is imported to mysql, but the text segment in the excel file is garbled at the original time, the total display error (the display data is too big, but it is actually an encoding error), so I want to filter out and delete all except letters, numbers, and common punctuation marks. I am thinking about the text-editing php string (text) filtering problem-regular expression
Which expert can delete all invalid characters except letters, numbers, and common punctuation marks.
Cause: A piece of excel file is imported to mysql, but the text segment in the excel file is garbled at the original time, the total display error (the display data is too big, but it is actually an encoding error), so I want to filter out and delete all except letters, numbers, and common punctuation marks.
I was thinking about how the text editors can insert a lot of content into the database?
------ Solution --------------------
You can use urlencode for encoding. invalid characters will not cause errors when being inserted to mysql. however, to correctly display the real data during select, you also need urldecode, this is a little troublesome. it depends on the requirements of the landlord.
------ Solution --------------------
1. enabling the mb extension is generally enabled.
2. obtain the encoding type of a string.
3. convert to the encoding you need
4. normal database insertion
------ Solution --------------------
Preg_match_all ('/\ w +/', $ str, $ out );
Print_r ($ out); // The output here is an array
$ Newstr = implode ('', $ out); // This is the string.