javascript - HTML Special Characters and PHP
886
I have a span that contains and upper arrow:▲
Via an AJAX call, in PHP, I receive a POST parameter that contains this arrow.
$("#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);
});
});
In PHP, I am simply checking if the parameter is this arrow.
if(isset($_POST['arrow']){
$arrow = $_POST['arrow'];
if($arrow=='▲')
echo 'Its an arrow';
else
echo 'Its not an arrow';
}
The JS returns an alert box 'Its not an arrow'. Am I comparing it in the right way?
Answer
Solution:
$(this).html();
returns the actual Unicode character▲
instead of the character escape▲
.You can check the length to see this:
Next, you send this character to the backend. And all AJAX data is encoded as UTF-8. UTF-8 representation of
▲
isE2 96 B2
.