PHP quotes inside quotes

后端 未结 3 1334
天涯浪人
天涯浪人 2020-11-28 16:18

Is it possible to put quotes inside quotes?

If so how?

Here is my code:



        
相关标签:
3条回答
  • 2020-11-28 17:15

    According to php.net

    To specify a literal single quote, escape it with a backslash (\). 
    

    It means you could have:

    <?php
      echo '<span onclick="$(this).addClass(\'selected\');"> </span>';
    ?>
    
    0 讨论(0)
  • 2020-11-28 17:15

    Heredoc is the perfect solution for this:

    <?php
    echo <<< HereDocString
        <span onclick="$(this).addClass('selected');"> </span>
    HereDocString;
    ?>
    
    0 讨论(0)
  • 2020-11-28 17:16

    You could do this:

    <?php
      // some code
    ?>
    
        <span onclick="$(this).addClass('selected');"> </span>
    
    <?php
      // some more code.
    
    ?>
    
    0 讨论(0)
提交回复
热议问题