 <p>When you are printing the php variables it prints only the variable, so if $title equals Hello the Java Script interpreter think there a variable in Java Script named Hello. To avoid this you have to print into the HTML the variable value inside quotes.</p> <pre><code>$string = 'World!'; $title = 'Hello'; echo '&lt;a href="#" onclick="doSomething(\'' . $title . '\', \'' . $string '\')" id="'.$title.'" return false;" title="'.$title.'"&gt;'.$title.'&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;'; </code></pre>