您好,欢迎访问一九零五行业门户网

php 字符变换

php 字符转换
插入数据
将单引号(') 前加上\ ,避免数据库插入错误.? 相关函数 : addcslashes($str,'\'');
读取数据
将 &,这三个字符转换成html实体(如不改变,在xml中将报错)相关函数: htmlentities($str,ent_noquotes);? //ent_noquotes的意思是不转换 双引号() 和 单引号(')
乱码
大部分乱码都是因为编码不一致造成的,可使用相关函数重新进行编码相关函数: icovn(utf-8,ascii//translit//ignore,$str);? // translit 和 ignore 是 参数,分别是遇到特殊字符时停止编码,返回已编码的字符串 和 忽略不能编码的字符.
echo '/************addcslashes************/';$str = 'abcdfegadsf\'asdfasdfa';echo addcslashes($str,'\'');echo '/************htmlentities*************/';$str = 'abcdfe & s ha \'asdfasdfa';echo htmlentities($str,ent_noquotes);echo '/************iconv*************/';$str = ' ‘ ’ ?“?”¨ ? ? ? ? ? ? @ @wei?, goldmann, g?bel, weiss, g?the, goethe und g?tz ? aa';//change encoding from utf-8 to asciiecho iconv('utf-8','ascii//translit//ignore',$str);
其它类似信息

推荐信息