网中网 发表于 2017-3-28 12:45:40

乱码处理特别心得(2)--php相关

  需求:在url中传送有汉字参数,
解决方法:
(1)所有的PHP,js,css,html等文件都用utf-8编码。mysql建库时也用utf-8编码
(2)php文件的开头使用
     header("Content-Type:text/html; charset=UTF-8");
(3)用户提交表单的页面用js
   a.php
     <script>
       function commit() {
         var par = document.form1.name.value;
         window.location.href = 'b.php?name=' + encodeURI(par);
       }
     </script>
    
     <body>
     <form name="form1">
       <input type="button" name="name" value="" />
       <input type="button" value="提交"/>
     </form>
     </body>
(4)b.php
   echo $_GET['name']; //无需任何处理
页: [1]
查看完整版本: 乱码处理特别心得(2)--php相关