Search code examples
phphtmlquotesquoteaddslashes

Solving simple quotes and 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 :)


Solution

  • 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