问题
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 there's a quote clash whether I use double quotes or single quotes. Is there any way to assign this string to a var without having to manually add slashes to all the quotes?
It could be something like this:
<div class="name">Sally O'Connel</div>
Only the string is longer so there will be multiple occurances of single quotes and double quotes.
回答1:
You could use HEREDOC/NOWDOC:
$var = <<<HTML
<div class="name">Sally O'Connel</div>
HTML;
回答2:
$var = file_get_contents('file.with.your.long.and.windy.html');
would be apparently the only sane way. PHP files are for the code.
回答3:
use Heredoc
$var = <<<HTML
<div class="name">Sally O'Connel</div>
HTML;
Please ensure that there is no space character after HTML;
来源:https://stackoverflow.com/questions/23885155/php-work-with-a-large-string-with-quotes