Blogger Information
Blog 30
fans 0
comment 0
visits 18256
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
4.11 初识php
宋的博客
Original
499 people have browsed it

实例

<meta charset="utf-8">
<?php

echo '<h2 style="color:red">hello php</h2>';

//双引号包装的字符串可解析内部的变量名
$mobai = '7.5亿美元现金';
echo '美团$mobai收购了膜拜单车';
echo '<hr>';
echo "美团{$mobai}收购了膜拜单车";
echo '<hr>';
// 转移字符:\,回车\r,换行\n,制表符\t,美元符\$
echo "胡玮炜:\\表示不存在所谓的\n\$\"出局\"";
echo '<hr>';
//换行符默认解析为空格<br>,需要看到效果需要用nl2br
echo nl2br("胡玮炜:\\表示不存在所谓的\n\$\"出局\"");
echo '<hr>';

//变量中加转义符后,不会解析
$sitename = 'php中文网';
echo "$sitename";
echo '<hr>';
echo "站点:{$sitename}";
echo '<hr>';
echo "站点:{\\$sitename}";
echo '<hr>';


//heredoc结构,可以将变量和特殊字符自动转义
$heredoc = <<<aaa
{$sitename}:\r\nPHP是最好的学习平台
aaa;
echo $heredoc;
echo '<hr>';
echo nl2br($heredoc);

//NOWDOC,将内容原样输出,不解析变量和特殊字符
echo '<hr>';
$NOWDOC = <<< 'NOWDOC'
<h3>$sitename</h3>\r \n 'php.cn'
NOWDOC;

echo $NOWDOC;
echo '<hr>';
echo nl2br($NOWDOC);

运行实例 »

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


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