【问题标题】:php not sense to special charactersphp对特殊字符没有意义
【发布时间】:2015-03-08 14:57:18
【问题描述】:
<?php
mb_detect_order('UTF-8,eucjp-win,sjis-win');
mb_internal_encoding('UTF-8');
echo mb_internal_encoding();
function convert($a) str_replace('â','a',$string);
$e=$_POST['aaa'];

 ?>
<!doctype html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" >
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>
<form method="post" action="#">
<textarea id="aaa" name="bbb" placeholder="send"  ></textarea>

**mb_internal_encoding();输出:“UTF-8”

文本区域输入:“âb” || php-output:âb 脚本不转换 "â"=>"a"

文件没有 BOM**

这些可能是其他原因??我还能尝试什么?

【问题讨论】:

  • 你的问题是什么??发布代码和错误永远不会得到解决方案,发布您尝试实现的目标以及您遇到的错误
  • 脚本不转换 â=>a
  • 试试var_dump(bin2hex('â'))并告诉我们结果。
  • 脚本在本地主机和其他主机上正确转换,但在我的主机上不能转换特殊字符

标签: php encoding special-characters mbstring


【解决方案1】:
str_replice('â','a',$string);

应该是:

 str_replace('â','a',$string);

【讨论】:

  • 对不起,我写错了,在脚本中:“str_replace”
【解决方案2】:

有些错别字:

function convert($a) str_replice('â','a',$string);

应该是:

function convert($a){return str_replace('â','a',$a);}

不是 replice(),$string 应该是 $a ,如果你想看到函数的输出你应该 return 它。

所以当你打电话时:

<?php echo convert("â");?>

它会输出就好了

【讨论】:

  • 对不起,我写错了,在脚本中:“str_replace”
  • @user1419633,如果你尝试理解我的回答,那么你的问题就解决了,这行function convert($a){return str_replace('â','a',$a);} 说明了一切;)
  • 没解决,不是语法问题。在某些服务器脚本上正常运行。真正的代码“str_replace”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-23
  • 2014-10-18
  • 2016-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多