php字符串(文本)过滤有关问题-正则表达式

WBOY
Release: 2016-06-13 10:01:25
Original
693 people have browsed it

php字符串(文本)过滤问题-正则表达式
哪位高手给段可以删除 字母、数字、常用标点符号以外所有非法字符的代码。

原因:处理一段在excel的文件导入到mysql,但是excel文件中的文本段,在原来的时候就已经乱码了,所以插入的时候,总显示错误(显示数据太大,其实就是编码错误),所以想把除了字母、数字、常用标点符号之外都过滤删除掉。

我自己在想,那些文本编辑器可以把很多内容都插入到数据库中,他是怎么实现的呢?

------解决方案--------------------
可以使用urlencode进行编码,那些非法字符就不会在insert到mysql的时候出错了,不过要正确在select的时候显示真实的数据,还需要urldecode一下,这点有点麻烦啊,看楼主的需求了
------解决方案--------------------
1、开启mb扩展,一般都是开启的
2、获取字串的编码类型
3、转换为你需要的编码
4、正常插入数据库
------解决方案--------------------
preg_match_all('/\w+/',$str,$out);
print_r($out);//这里输出的是数组
$newstr = implode('',$out);//这样就是字串了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!