Blogger Information
Blog 41
fans 2
comment 1
visits 26165
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0411作业
郭恒的博客
Original
574 people have browsed it

实例

<?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.
 */

运行实例 »

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


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
  • 2018-03-16 15:12:44