Quotes in js - again

I have this (in php):
$text=“test’it”;

and later this:
“<input…onclick='test(\”“.$text.”\“);'>”

and test() is:
function test(a){alert(a);}

The function doesn’t display anything with “test’it” but displays “test it” ok. Htmlentities doesn’t fix it and I can’t find any other solution.
Thanks

First question: Did you put <input… inside the <php?..brace? That is the only way you can add $text to the js mothod. Unless I am wrong. Someone chime in…

Yes. More fully it’s:
<?php
$text=“test’it”;

echo “<input…onclick='(\”“.$text.”\“);'>”;
?>
I tried addslashes($text) as well as htmlentities but still no good.

Try adding:
$text = $text.replace(/\'/g, “&#39”);

Right after $text = “test’ it”;

&#39 is the HTML code for the apostrophe. Remember, you’re concatenating two strings through PHP which then get “unstringed”. Lol it’s confusing but here’s a visualization of what’s happening:

<input...onclick=' (\\ " test' it ' " );'>
_________________------------____-------__

Underscores are regular characters and hyphens are strings.

Thanks OMGCarlos. I’ve tried it once and it didn’t work, but I’ll get back to it later.