Blogger Information
Blog 9
fans 0
comment 0
visits 7716
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php中的字符串中的变量解析
漠漠
Original
1527 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">
<!--    php动态生成标题-->
    <title><?php echo '字符串的变量解析'?></title>
</head>
<body>
    <?php
    $money='90亿美元';//用单引号定义一个字符串变量$money
    $title1="阿里巴巴{$money}收购饿了么";//用双引号定义一个字符串变量$title1,并且可以在字符串中直接插入一个变量,而不用使用拼接符。
    $title2='阿里巴巴{$money}收购饿了么';/*用单引号定义一个字符串变量$title2,如果要在定义的字符串中插入一个变量,不能直接插入,必须要
                                           使用 . 作为拼接符来拼接一个变量,如$title3*/
    $title3='阿里巴巴'.$money.'收购饿了么';
    echo $title3,'<br>';
//    echo $title1 , '<br>' , $title2 , '<br>';
    echo $title1, '<br>', $title2, '<br>';

    $title4='阿里巴巴收购\'饿了么\'';/*单引号和双引号是定义字符串变量的定界符,如果被定义的字符串中需要用到单引号或者双引号,那么就要使用转义字符 \
                                       例如$title4中的单引号'就需要用\'来表示*/
    echo $title4 ,'<br>';
    $title5='阿里巴巴收购"饿了么"';//在单引号定义的字符串中想要输出双引号 无需用转移字符,如$title5
    echo $title5 ,'<br>';
    $title6="阿里巴巴收购'饿了么'";//同样的在双引号定义的字符串中想要输出单引号 也无需使用转义字符,如$title6
    echo $title6 ,'<br>';

    //heredoc的语法结构和用法
    echo <<<"HEREDOC"
$title3 \n \r \t //这里输出的变量后面不用加 分号; 就算是我写的这些条注释,<br>也会被输出<br>
HEREDOC;
    //nowdoc的语法结构和用法
    echo <<<'NOWDOC'
 $title1//相当于单引号包装的字符串
NOWDOC;
    
    ?>
</body>
</html>

运行实例 »

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


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