Home > Backend Development > PHP Tutorial > php 字符变换

php 字符变换

WBOY
Release: 2016-06-13 10:49:15
Original
895 people have browsed it

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);
    Copy after login
    ?

    ?

    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