zoukankan      html  css  js  c++  java
  • PHP — 基础语法

    一、PHP 标记

    当解析一个文件时,PHP 会寻找起始结束标记,也就是<?php?>,在标记外的部分会被解析器忽略。

    注意

    开始标记后面必须跟上一个空白符,否则就会出错。

    二、从 HTML 中分离

    凡是在PHP开始和结束标记之外的内容,都会被PHP解析器忽略。例外是使用控制语句时:

    <?php $expression = TRUE; ?>
    <?php if ($expression == true): ?>
      This will show if the expression is true.
    <?php else: ?>
      Otherwise this will show.
    <?php endif; ?>
    <!-- 输出为:This will show if the expression is true. -->

    三、指令符分隔

    使用分号分隔语句,最后一条语句的分号可以省略。

    四、注释

    PHP注释有3种类型:

    // 单行注释
    # 单行注释
    /*
        多行注释
    */
    • 多行注释的内容从/*开始,至*/结束,因此多行注释不能嵌套。

    • 单行注释的内容从//或#开始,至行末结束,或者遇到?>则提前退出php解析。有时候这会导致一些问题:

      <?php
        $file_contents  = '<?php die(); ?>';
      ?>
      <!-- 正确将字符串`'<?php die(); ?>'`赋值给`$file_contents` -->
    
      <?php
        // $file-contents = '<?php die(); ?>';
      ?>
      <!-- php至第一个`?>`就退出解析,后面的`'; ?>`属于html的一部分 -->
  • 相关阅读:
    121. Best Time to Buy and Sell Stock
    玩转算法2.3常见的算法复杂度分析
    数组中的逆序对
    一些基本的代码模板
    230. Kth Smallest Element in a BST
    42. Trapping Rain Water
    api token
    仿百度查询
    baidu jsonp
    How to fix Error: laravel.log could not be opened?
  • 原文地址:https://www.cnblogs.com/yuyu99/p/6391139.html
Copyright © 2011-2022 走看看