PHP:使用带有引号的大字符串 [英] PHP: Work with a large string with quotes
本文介绍了PHP:使用带有引号的大字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
php var
,但是有一个引号冲突,无论我使用双引号还是单引号。有没有办法将这个字符串分配给一个var,而无需手动向所有引号添加斜杠? 可能是这样的:
< div class =name> Sally O'Connel< / div>
只有字符串更长,所以会出现单引号和双引号的多次发生。
解决方案
您可以使用 HEREDOC / NOWDOC :
$ var =<< HTML
< div class =name> Sally O'Connel< / div>
HTML;
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.
解决方案
You could use HEREDOC/NOWDOC:
$var = <<<HTML
<div class="name">Sally O'Connel</div>
HTML;
这篇关于PHP:使用带有引号的大字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文