Home Backend Development PHP Tutorial PHP学习总结--2015.7.5

PHP学习总结--2015.7.5

Jun 23, 2016 pm 01:31 PM

一、PHP开头基础

  使用 var_dump 来获取真正的数据类型;

  例: var_dump ($flag);

   echo "
"; // 光标跳转到下一行;

1,什么是PHP:

   PHP,一个嵌套的缩写名称,是英文超级文本预处理语言(PHP:Hypertext Preprocessor)的缩写.

2,ECHO语句:

   echo 语句是PHP中的输出语句,代码如下:

   

  echo "1234";

    ?>

3,连接符“.”

 

  echo "hi"."inout";

   ?>

  结果:hiinout;

4,注释:

 在PHP中用//来表示注释。但是注释必须在之间。

二、变量

1,变量

  A.变量可以复制,但是他只保留最后一次的值;

  B.定义变量:

   

   $var_namu = "231414";

   变量名            变量值(此处为字符串型)

      ?>

 C.命名规则:

    a.以$进行标识。

   b.以字母或下划线开头;

   c.变量名可以由字母、数字、下划线(英文)、汉字组成。

   d.变量名不许含有空格,当变量名由多个单词组成时可用下划线(英文)连接。

   e.变量名区分大小写。

2.变量的数据类型。

  变量的类型便是数据的类型。例如超市的包装袋。不同的商品要使用不同的包装袋。不同的变量也要规定不同的变量类型。

  定义四种常用的变量类型:

   A.$var_string = "123";  定义字符串型变量。

   B. $G = "1231313" ; 定义整形变量。

   C. $F = "123.554"  ;  定义浮点型数据。

   D.$faf = array("123");定义数组;定义数组需要array(),标识;

3.在PHP中,支持8种原始类型,其中包括四种标量类型,两种复合类型和两种特殊类型;

   ①、布尔类型????????标量

    布尔只有两个值,一个是ture另一个是false。不区分大小写,主要用于条件结构中;

   ②、整型??????标量

    整型(integer):类似于常见的整数,十进制,八进制,十六进制。八进制前加 0;十六进制前加 0x;

   ③、浮点型??????标量

   浮点型(浮点数、双精度数或实数),即通常所说的小数。可以用小数点或者科学计数法表示,e和E等价;

     例:

            $num_float = 1.234;

            $mun_float2= 1.234*10e9;

 

            ?>

    ④、字符串??????????标量

       

     A,字符串是由一系列字符组成,在PHP中,字符和字节一样,也就是说,一共有256种不同的可能性;字符串可以用三种方法定义,单引号,双引号,heredoc结构形式:

       

          $str_string1 = '我要成为PHP大牛';

          $str_string2 = "我一定可以在本月中旬找到PHP的工作";

         ?>

 

 

       B,字符串中包含单引号和双引号是的处理方式;

     

       $str_string1= '"12312"';       //单引号拥抱双引号;

       $str_string2 = "'guahugaghu'";      //双引号拥抱单引号;

       $str_string3 = "\"ghasgaho\"";  //双引号拥抱双引号;

        $str_string4 = '\'huwsehraw\''; //单引号拥抱单引号;

       ?>

          

       C.字符串中包含变量时:

    当双引号中包含变量时,则双引号内容与变量内容链接在一起输出,若单引号中包含变量时,则变量名以字符串形式输出;

     

       $love = "huozhe";

       $love1 = "woyao,$love";

       $love2 = 'woyao,$love';

        echo $love1;

        echo  "
";

        echo $love2;

      >

  运行结果:woyao,huozhe

               woyao,$love

 

 

 

  D.当要输出的字符串很长时,可以用heredoc结构解决;

 

   $data_string =

                   使用的字符串,想输多少都可以;

                  my;

  ?>

 ⑤资源??????特殊类型

  资源(resource) :资源是由专门的函数来建立和使用的,例如打开文件,数据连接。图形画布。我们可以对资源进行操作(创建,使用和释放)。任何资源,在不需要的时候都应该被及时释放,如果忘记了释放资源,系统便会启动垃圾回收机制,在页面执行完毕后回收资源,以避免内存被消耗殆尽。

  例: $file_handle = fopen("data/php/f.txt","r"); //采用fopen函数打开文件夹,得到返回值则证明打开的位置确实是资源类型;

⑥ 空????特殊;

   null;

  被赋值为NULL,尚未被赋值的变量,被释放的变量(unsettle($werwq));

 例: $wqerqiou = NULL;

        $FDSF = " ";

         unset($FDSF);

 

 

三 、 常量;

  常量可以理解为值不变的量(如同圆周率),或者常量被定义后,在脚本的其他地方不可以被改变的量。PHP中常量被分为自定义常量和系统常量;

  

  自定义常量,根据我们开发的需要而定义的常量,他通过使用函数 define()定义;

  例  ①define("PI",3.14)  ==  define ("常量名",常量值);

       ②$q = "PI";

          define($q,3.14);  ==  define ("常量名",常量值);

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

What is REST API design principles? What is REST API design principles? Apr 04, 2025 am 12:01 AM

RESTAPI design principles include resource definition, URI design, HTTP method usage, status code usage, version control, and HATEOAS. 1. Resources should be represented by nouns and maintained at a hierarchy. 2. HTTP methods should conform to their semantics, such as GET is used to obtain resources. 3. The status code should be used correctly, such as 404 means that the resource does not exist. 4. Version control can be implemented through URI or header. 5. HATEOAS boots client operations through links in response.

How do you handle exceptions effectively in PHP (try, catch, finally, throw)? How do you handle exceptions effectively in PHP (try, catch, finally, throw)? Apr 05, 2025 am 12:03 AM

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

What are anonymous classes in PHP and when might you use them? What are anonymous classes in PHP and when might you use them? Apr 04, 2025 am 12:02 AM

The main function of anonymous classes in PHP is to create one-time objects. 1. Anonymous classes allow classes without names to be directly defined in the code, which is suitable for temporary requirements. 2. They can inherit classes or implement interfaces to increase flexibility. 3. Pay attention to performance and code readability when using it, and avoid repeatedly defining the same anonymous classes.

What is the difference between include, require, include_once, require_once? What is the difference between include, require, include_once, require_once? Apr 05, 2025 am 12:07 AM

In PHP, the difference between include, require, include_once, require_once is: 1) include generates a warning and continues to execute, 2) require generates a fatal error and stops execution, 3) include_once and require_once prevent repeated inclusions. The choice of these functions depends on the importance of the file and whether it is necessary to prevent duplicate inclusion. Rational use can improve the readability and maintainability of the code.

Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles