Blogger Information
Blog 24
fans 0
comment 0
visits 15252
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0411作业
小蚂蚁的博客
Original
698 people have browsed it

<?php

/**

 * 定界符;单引号,双引号

 * 单引号:内容原样输出

 */


// 创建变量

 $money='95美元';

 $title1='阿里$money收购饿了么';


// 双引号做定界符来包装字符串

// money收购了饿了么当成变量

// $title2="阿里$money收购饿了么";

 $title2="阿里{$money}收购饿了么";

 // echo $title;

  echo $title1,'<hr>',$title2;


  echo '<hr>';


  // 特殊字符:如何在字符串中输出定界符!

  // 转义用\线

   echo '周星驰说:\'我愿向上天再借500年\'';

   echo'<hr>';

   echo "周星驰说:\"我愿向上天再借500年\"";


   // 特殊字符:\n换行符

   echo '<hr>';

   //  单引号不会解析特殊字符,原样输出

   echo '明天会下雨吗?\n 不会的';

 // \n在页面中解析为空格,只有解析为空格时才会换行!

   echo "明天会下雨吗?\n 不会的";

  // nl2br(string)将字符串中的\n解析为<br>

  echo '<hr>';

   echo nl2br("明天会下雨吗?\n 不会的");


   echo '<hr color="red">';

// 如果不希望变量不解析

   $title2="阿里{\$money}收购饿了么";


//heredoc, nowdoc

/**

 *  heredoc

 *  功能;与双引号创建是一样的,解析变量与特殊字符

 *  内部的双引号不需要转义

 */

 echo '<hr>';

 $siteName='好好学习';

 // $heredoc = <<< HEREDOC

 $heredoc = <<< "HEREDOC"

{$siteName}好好学习,"天天"向上 \n跟着php中文网一起前进!

HEREDOC;

 echo nl2br($heredoc);

 /**

  * nowdoc: 对应着单引号功能:原样输出,单引号也不用转义

  * 支持版本php5.3+

  */

//  

   echo '<hr color="red">';

   $nowdoc = <<< 'NOWDOC'

<h3>$siteName</h3> \r\n 'www.php.cn'

NOWDOC;


echo '<hr>';

echo $nowdoc;

实例

<?php
/**
 * 定界符;单引号,双引号
 * 单引号:内容原样输出
 */

// 创建变量
 $money='95美元';
 $title1='阿里$money收购饿了么';

// 双引号做定界符来包装字符串
// money收购了饿了么当成变量
// $title2="阿里$money收购饿了么";
 $title2="阿里{$money}收购饿了么";
 // echo $title;
  echo $title1,'<hr>',$title2;

  echo '<hr>';

  // 特殊字符:如何在字符串中输出定界符!
  // 转义用\线
   echo '周星驰说:\'我愿向上天再借500年\'';
   echo'<hr>';
   echo "周星驰说:\"我愿向上天再借500年\"";

   // 特殊字符:\n换行符
   echo '<hr>';
   //  单引号不会解析特殊字符,原样输出
   echo '明天会下雨吗?\n 不会的';
 // \n在页面中解析为空格,只有解析为空格时才会换行!
   echo "明天会下雨吗?\n 不会的";
  // nl2br(string)将字符串中的\n解析为<br>
  echo '<hr>';
   echo nl2br("明天会下雨吗?\n 不会的");

   echo '<hr color="red">';
// 如果不希望变量不解析
   $title2="阿里{\$money}收购饿了么";

//heredoc, nowdoc
/**
 *  heredoc
 *  功能;与双引号创建是一样的,解析变量与特殊字符
 *  内部的双引号不需要转义
 */
 echo '<hr>';
 $siteName='好好学习';
 // $heredoc = <<< HEREDOC
 $heredoc = <<< "HEREDOC"
{$siteName}好好学习,"天天"向上 \n跟着php中文网一起前进!
HEREDOC;
 echo nl2br($heredoc);
 /**
  * nowdoc: 对应着单引号功能:原样输出,单引号也不用转义
  * 支持版本php5.3+
  */
//  
   echo '<hr color="red">';
   $nowdoc = <<< 'NOWDOC'
	<h3>$siteName</h3> \r\n 'www.php.cn'
NOWDOC;

echo '<hr>';
echo $nowdoc;

运行实例 »

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


Correction status:Uncorrected

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