批改状态:合格
老师批语:
<?php header('content-Type: text/html; charset=UTF-8'); ?>
<?php
/*
* 界定符:单引号,双引号
* 1.单引号:内容原样输出
*/
//创建变量
$money = '要吃饭';
$title1 = '我$money,你饿了么';
//双引号做界定符来包装字符串
$title2 = "我{$money},你饿了么";
echo $title1, '<hr>', $title2;
echo '<hr>';
//特殊字符:如何在字符串中输出界定符?转义
echo '哈哈:\'你好 \'';
echo '<hr>';
echo "哈哈:\"你好\"";
//特殊字符:/n
echo '<hr>';
//单引号不会解析特殊字符,原样输出
echo '明天会下雨么?\n 不会的';
echo '<hr>';
//\n在页面中解析为空格,只有在源码中才有换行
echo "明天会下雨么?\n 不会的";
//nl2br(string)将字符串中的\n解析为<br>
echo '<hr>';
echo nl2br("明天会下雨么?\n 不会的");
echo '<hr color="red">';
echo $title2 = "我{$money},你饿了么";
echo '<hr color="red">';
//heredoc, nowdoc
/*
* heredoc
* 功能:与双引号创建字符串是一样的,解析变量与特殊字符
* 内部的双引号不需要转移
*/
$stiteName = '郭恒';
$heredoc = <<< "HEREDOC"
{$stiteName}就是我。\n
"哈哈!"
HEREDOC;
echo $heredoc;
echo '<hr color="red">';
echo nl2br($heredoc);
/*
* nowdoc:对应单引号功能:原样输出,单引号也不能转义
*
*/
echo '<hr color="blue">';
$nowdoc = <<< 'NOWDOC'
<h2>$stiteName</h2>\r\n 'www.php.cn'
NOWDOC;
echo $nowdoc;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号