try with htmlspecialchars($value,ENT_QUOTES);
it's better also to get rid of all these slashes:
?>
<span onclick='search("<?=htmlspecialchars($value,ENT_QUOTES);?>");'>
some stuff
</span>
<?php
// back to php
문제
Sorry if that question has been already answered but what i found on the internet didn't help me that much.I got a problem with php and simple quotes
Here is my code :
echo "<span onclick='search(\"".$value."\");'>".some stuff."</span>";
My problem is that $value is sometimes with simple quotes (they are music titles). So i got some problems with 't' stands for trouble, can't stand losing you ...
I tryed with addslashes($value)
but it does not work.
Any idea ?
Thanks :)
해결책
try with htmlspecialchars($value,ENT_QUOTES);
it's better also to get rid of all these slashes:
?>
<span onclick='search("<?=htmlspecialchars($value,ENT_QUOTES);?>");'>
some stuff
</span>
<?php
// back to php
다른 팁
Maybe you can HTML encode ( http://php.net/manual/en/function.htmlentities.php ), it will make HTML entities out of the special characters in your titles. Be sure to decode on the recieving end though.
str_replace("'", "'", $value);
should change quotes to their XML entity...
You may use htmlentities function:
echo "<span onclick='search(\"".htmlentities($value, ENT_QUOTES)."\");'>".some stuff."</span>";
your proper syntax should be something like this. Use htmlentites($value,ENT_QUOTES) to handle the special characters
$sanitizedValue = htmlentites($value,ENT_QUOTES);
echo "<span onclick='search(\"{$sanitizedValue}\");'>some stuff</span>";