PHP Echo - Escaping quotes

后端 未结 4 1047
不思量自难忘°
不思量自难忘° 2021-01-25 22:46

I was programming something in PHP but since I\'m a newbie I got stuck.

I have no clue how should I escape quotes on the following line. Moreover, I think the PHP tags i

相关标签:
4条回答
  • 2021-01-25 23:22

    I am boot sure what DoNav does but I think you want to have this line instead:

    echo '<tr onclick="DoNav(\'list.php?id=' . $row['ID']. '\');">';
    

    In PHP the \ is the escape character. If you want to escape a " you can write \"

    I hope it was helpful. Good luck

    0 讨论(0)
  • 2021-01-25 23:29

    The general/common escape character is \, works in PHP and Javascript.

    echo '<tr onclick="DoNav(\'list.php?id=' . $row['ID'] . '\');">';
    
    0 讨论(0)
  • 2021-01-25 23:37

    Escape with a backslash, use "." for concatenation.

    $row = array();
    $row['ID'] = 1;
    
    echo '<tr onclick="DoNav(\'list.php?id=' . $row['ID']. '\');">';
    

    Output

    <tr onclick="DoNav('list.php?id=1');">
    

    Also make sure to escape any content you're going to use in Javascript or HTML. For an ID, you might just cast as an integer:

    echo '<tr onclick="DoNav(\'list.php?id=' . (int)$row['ID']. '\');">';
    

    Strings'll be more important to escape.

    0 讨论(0)
  • 2021-01-25 23:37

    This u need

    echo '<tr onclick="DoNav(\'list.php?id='.$row['ID'].'\');">';
    
    0 讨论(0)
提交回复
热议问题