Blogger Information
Blog 17
fans 0
comment 0
visits 13677
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP搭建环境与基本语法的学习 8月21号
18674060620的博客
Original
888 people have browsed it

今晚终于讲到php部分了,今晚跟老师学习了PHP环境搭建与基本语法(字符串的创建与变量解析)

手写代码

20180822150700.jpg

 编程: 实例演示php中的字符串中的变量解析,特殊字符转义,以及heredoc和 nowdoc语法结构的用法

实例

<?php
//字符串

$money = '95亿美元';
//$title1 = '阿里'.$money.'收购了饿了么';
$title1 = '阿里$money收购了\'饿了么\'';
$title2 = "阿里{$money}收购了\\\"饿了么\"";

echo $title1, '<br>', $title2, '<br>';
echo nl2br($title2);

echo '<hr>';

//heredoc
// heredoc 等价使用了双引号的字符中,可以解析内部的变量和转义特殊字符
echo  <<< "HEREDOC"
{$title2} \n  \r \t 
HEREDOC;

// nowdoc
// 相当于用单引号包装的字符串
echo <<< 'NOWDOC'
{$title2} \n  \r \t
<h3><a href="">Hello 老师晚上好</a></h3>
NOWDOC;

运行实例 »

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


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!