Blogger Information
Blog 5
fans 0
comment 0
visits 3306
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php字符串的变量解析,特殊字符转义,heredoc和 nowdoc语法结构的用法--2018年8月23日14点23分作业
小鱼的博客
Original
764 people have browsed it

1、代码实践

实例

<?php
/**
 * 字符串
 */
$money = '95亿美元';
$title = '阿里'.$money.'收购了饿了么';  //.语法叫字符串的拼接符,连接符。
$title1 = "阿里{$money}收购了饿了么";
$title2 = '阿里{$money}收购了饿了么';
$title3 = "阿里{$money}收购了\"饿了么\"";
$title4 = '阿里{$money}收购了\'饿了么\'';
$title5 = "阿里{$money}收购了\\'饿了么\'";
echo $title;
echo '<hr>';
echo $title1;
echo '<hr>';
echo $title2;
echo '<hr>';
echo $title3;
echo '<hr>';
echo $title4;
echo '<hr>';
echo $title5;
echo '<hr color="pink">';

//heredoc
//heredoc 等价使用了双引号的字符中,可以解析内部的变量和转义特殊字符
echo <<< HEREDOC
{$title1} \n  \r \t
HEREDOC;
echo '<hr color="red">';
//nowdoc
//相当于用单引号包装的字符串
echo <<< 'NOWDOC'
{$title2} \n  \r \t
<h3><a href="">hello  同学们晚上好呀!</a></h3>
NOWDOC;

运行实例 »

点击 "运行实例" 按钮查看在线实例

2、实例截图

微信截图_20180823142646.png

3、手抄截图

微信图片_20180823142744.jpg

4、学习小结

学习PHP变量名的命名规则,变量名严格区分大小区,函数不区分大小写

Correction status:qualified

Teacher's comments:注意:这里的heredoc和nowdoc与前面的<<<符号之间不需要有空格的!
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