Hi im new here and i need help with the quotes of this code:

               print("<tr><td><a href='#' onclick="document.getElementById('name').value = '$dirArray['index']';'>$dirArray[$index]</a></td>");

I got the code right but the quotes i can't seem to get it right.
Please help me with this 😃

    Since you are using double quotes to delimit the string literal, you should escape double quotes within the string literal by prepending a backslash for each of them. Also, because you are interpolating this array element within the string, $dirArray['index'] should be $dirArray[index] (though the quotes should be used when it is placed outside of a string).

      Also you can use {$dirArray['index']} when used within double quotes or heredoc syntax.

        I did what you both said above this post but i still get the error.

          print("<tr><td><a href='#' onclick='document.getElementById('name').value = '{$dirArray['index']}';'>{$dirArray['index']}</a></td>");
          

          You opened onclick with double quote and tried to close with single. Switched to both single. try that.

            wrote:

            You opened onclick with double quote and tried to close with single. Switched to both single. try that.

            Good observation, but the suggested solution is not correct.

            In this case, a printf might be better:

            printf('<tr><td><a href="#" onclick="document.getElementById(\'name\').value = \'&#37;1$s\';">%1$s</a></td>',
                htmlspecialchars($dirArray['index']));
              Write a Reply...