Php 如何使用单引号放置参数(可以是str或int)

Php 如何使用单引号放置参数(可以是str或int),php,Php,我无法在$r变量中传递任何字符串。它必须是整数才能工作 echo '<tr> <td><input type="submit" name="voirListe" value="O" onClick="javascript:listeFormulaire('.$r['username'].');"> [...] </tr>'; 它会起作用的 但这个不起作用…语法错误 onClick="java

我无法在$r变量中传递任何字符串。它必须是整数才能工作

echo '<tr>
        <td><input type="submit" name="voirListe" value="O" onClick="javascript:listeFormulaire('.$r['username'].');">            
  [...]
      </tr>';
它会起作用的

但这个不起作用…语法错误

onClick="javascript:listeFormulaire(\'.$r['username'].\');"

告诉我,伙计们,我如何传递一个字符串参数?

你们可以在下面的代码中尝试,在最后的代码中尝试“urmissing”

onClick="javascript:listeFormulaire(\'.$r['username'].\');" 
试试这个

<?php
echo '<tr>
        <td><input type="submit" name="voirListe" value="O" onClick="javascript:listeFormulaire('.$r[username].');">            
      </tr>';
?>

我添加了一些空间来看看到底发生了什么

echo '<input type="submit" name="voirListe" value="O" onClick="javascript:listeFormulaire(\'  '.$r['username'].'  \');">';
echo';

echo '<input type="submit" name="voirListe" value="O" onClick="javascript:listeFormulaire(\'  '.$r['username'].'  \');">';
<input type="submit" name="voirListe" value="O" onClick="javascript:listeFormulaire('<?php echo $r['username']; ?>')"; />