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, total display errors (the display data is too big, in fact, it is a 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service