PHP: Work with a large string with quotes

后端 未结 3 1999
时光说笑
时光说笑 2021-01-23 17:31

Suppose I have a large string of HTML code. It has both double quotes and single quotes. How can I work with such a string? I want to assign it to a php var but the

相关标签:
3条回答
  • 2021-01-23 18:22

    You could use HEREDOC/NOWDOC:

    $var = <<<HTML
    <div class="name">Sally O'Connel</div>
    HTML;
    
    0 讨论(0)
  •  $var = file_get_contents('file.with.your.long.and.windy.html');
    

    would be apparently the only sane way. PHP files are for the code.

    0 讨论(0)
  • 2021-01-23 18:35

    use Heredoc

    $var = <<<HTML
    <div class="name">Sally O'Connel</div>
    HTML;
    

    Please ensure that there is no space character after HTML;

    0 讨论(0)
提交回复
热议问题