HTML特殊字符与PHP

HTML特殊字符与PHP,php,javascript,jquery,html,special-characters,Php,Javascript,Jquery,Html,Special Characters,我有一个跨度,其中包含上箭头:▲ 在PHP中,通过AJAX调用,我收到一个包含此箭头的POST参数 $("#mySpan").click(function(){ var arrow = $(this).html(); alert(arrow); //displays the arrow the in an alert box $.post('Something.php',{ arrow: arrow },function(data){

我有一个跨度,其中包含上箭头:

在PHP中,通过AJAX调用,我收到一个包含此箭头的POST参数

$("#mySpan").click(function(){

      var arrow = $(this).html();
      alert(arrow); //displays the arrow the in an alert box
      $.post('Something.php',{ arrow: arrow },function(data){
            alert(data);
      });

});
if(isset($_POST['arrow']){

      $arrow = $_POST['arrow'];
      if($arrow=='▲')
            echo 'Its an arrow';
      else
            echo 'Its not an arrow';
}
在PHP中,我只是检查参数是否为这个箭头

$("#mySpan").click(function(){

      var arrow = $(this).html();
      alert(arrow); //displays the arrow the in an alert box
      $.post('Something.php',{ arrow: arrow },function(data){
            alert(data);
      });

});
if(isset($_POST['arrow']){

      $arrow = $_POST['arrow'];
      if($arrow=='▲')
            echo 'Its an arrow';
      else
            echo 'Its not an arrow';
}
JS返回一个警告框“它不是箭头”。我是否以正确的方式比较了它?

$(this.html()
返回实际的Unicode字符
而不是字符转义

您可以检查长度以查看以下内容:

alert($(this).html().length); // => 1
接下来,将此字符发送到后端。所有AJAX数据都编码为UTF-8。
e296 B2

echo $_POST['arrow'] === "\xE2\x96\xB2"; // Its an arrow

您可能需要使用类似URLDecode的方法来检查哪些数据是通过ajax发送的,并在ajax调用显示箭头之前检查
$\u POST['arrow']
@MatRt警报,如果我执行
echo$arrowecho$\u POST['arrow']='▲';,如果您将源代码保存为UTF-8。谢谢,但是有一点奇怪,如果我在比较中使用
“\xE2\x96\xB2”
,它是有效的,如果我使用
“\xE2\x96\xB2”
,它不起作用。@Ali Bassam,PHP将仅用双引号解释
\x..
序列。在单引号中,只能识别\'和\\。