Blogger Information
Blog 20
fans 0
comment 1
visits 14878
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php变量创建使用,解析,以及heredoc和 nowdoc语法结构的用法2018/08/21
南风的博客
Original
920 people have browsed it

实例

<!doctype html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title><?php  echo $title?></title>
        </head>
        <body>
        <?php
           echo '<h1>hello 中文网</h1>';
           ?>
        </body>
        </html>

<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/8/21
 * Time: 21:12
 */


/*
 *
 *超文本:html
 *
 *
 */

//定义一个变量
$name="hello";
echo $name;

$title="第一天来到php中文网学习php";

/**
 * htmL中通过<?php?>来输出php变量,但必须加入echo或print 输出
 *
*/



/**
 *  特殊字符转义 ,单引号不能解析,双引号会
 */
$titleName="我爱你中国";
echo $titleName;
echo  '<br>'.'<hr>';
//输出单引号
$titleName1='我爱你\'中国\'';
echo  "带单引号".$titleName1;

echo  '<br>'.'<hr>';
//输出双引号
$titleName2="我爱你\"中国\"";
echo  "带双引号".$titleName2;

//去掉转义符/,
echo  '<br>'.'<hr>';
$titleName3="我爱你\\\"中国\"";
echo  "去掉一个转义符".$titleName3;

echo  '<br>'.'<hr>';
/**
 *  heredoc和 nowdoc 的使用  heredoc和双引号类似可以解析,nowdoc和单引号类似不能解析
 */

$answer="你好,php中文网";

//使用heredoc输出需要解析的变量
echo  $heredoc=<<<HEREDOC
{$answer}
HEREDOC;

//使用nowdoc输出需要解析的变量
echo  <<<'NOWDOC'
{$answer}
NOWDOC;

?>

运行实例 »

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

手写:

QQ截图20180823185339.png

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