Blogger Information
Blog 31
fans 3
comment 1
visits 34591
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php对字符串的处理规则
php学习笔记
Original
1142 people have browsed it

1、单引号和双引号的区别

当输出字符串时,单引号中的内容原样输出,双引号可以解析变量和特殊字符。

举例如下:

<?php
$money = '3万';
echo '发朋友圈被罚{$money}';
echo '<hr>';
echo "发朋友圈被罚{$money}";

输出结果:

2018-04-12_100846.png

2.如果要在字符串中输出定界符需要用使用转义字符\

举例如下:

<?php
echo '子曰:\'学而时习之,不亦说乎\'';
echo '<hr>';
echo "子曰:\"学而时习之,不亦说乎\"";

输出结果:

1.png

3、heredoc和nowdoc

heredoc和nowdoc可以输出大段字符串,heredoc相当于双引号,nowdoc相当于单引号,而且heredoc中使用双引号不需要转义,nowdoc中使用单引号也不需要转义

举例如下:

<?php
$money = '3万';
$heredoc = <<<"HEREDOC"
奋达科技员工发朋友圈泄露公司机密被罚{$money}
HEREDOC;
echo $heredoc;
echo '<hr>';
$nowdoc = <<<'NOWDOC'
奋达科技员工发朋友圈泄露公司机密被罚{$money}
NOWDOC;
echo $nowdoc;

输出结果:

2018-04-12_103802.png


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post