PHP自学教程之PHP语法基础
一、PHP5.4的基本语法式 1、PHP注释与语法标识 (1)、单行注释 // 来源于C的注释 # 来源于C语言的注释 (2)、多行注释 /* */ 来源于C语言的注释 二、PHP5.4的变量与变量的数据类型 变量是由一个美元符“$开头,”$后是一个标识符。标识字符串只字母、数字
一、PHP5.4的基本语法格式
1、PHP注释与语法标识Copy after login(1)、单行注释 // 来源于C++的注释 # 来源于C语言的注释
(2)、多行注释 /* */ 来源于C语言的注释
二、PHP5.4的变量与变量的数据类型
变量是由一个美元符“$"开头,”$"后是一个标识符。标识字符串只字母、数字、下划线组成且不可以数字开头。
变量命名的方式<?php $php=true; //分号结束语句 if($php){ echo "真"; //分号结束语句 } //大括号结束语句 $url="blog.csdn.net/dawanganban"; //定义变量 echo $url; unset($url); //删除一个变量url echo $url; ?>Copy after login(1)单词之间直接连接
$titlekeyword
(2)单词之间用下划线连接
$title_keyword
(3)单词之间首字母大写(驼峰)
$titleKeyword
PHP的数据类型如下:
(1)字符串(String):单引号(简单引号)或双引号(功能引号)内的内容
(2)整型(integer): -2^32
(3)浮点符(float或double) 1.8E+308 (1.8 x 10^308)
(4)布尔型(boolean) true或false
(5)数组(Array)
(6)对象(Object)
<?php class Person{ public $userName="阳光小强"; public function getMsg(){ echo "姓名为:".$this->userName; } } $p=new Person(); $p->getMsg(); ?>Copy after login(7)资源类型(Resouce) 系统数据资源
资源是一个特殊的数据类型,无法直接获得变量,需要通过专门的函数来访问:
数据库访问必须通过Mysql函数库、Mysqli函数库或PDO函数库实现。
文件访问必须通过FileSystem函数库实现。
目录操作必须通过Directory函数库实现。
图像操作必须通过GD函数库实现。
(8)空值(NULL)
字符串引用单引号和双引号的区别?
两者的不同之处:双引号中所包含的变量会被自动替换成实际数值,而单引号所包含的变量则按照普通字符串输出。
三、PHP5.4的系统常量与自定义常量
常量在程序执行期间无法改变数据,常量的作用域是全局的。常量的命名与变量相似,只是不带“$"符号。一个有效的常量由字母或者下划线开头,一般在PHP中常量都为大写字母而且又分为系统常量和自定义常量。
系统常量范例:
__FILE__默认常量,是指PHP程序文件名及路径
__LINE__默认常量,是指PHP程序的行数
__CLASS__类的名称
在PHP中通过define()函数来定义一个常量,其语法格式为:
bool define(string $name, mixed $value [, bool case_$insensitive])
name:常量的名称
value:常量的值
insensitive:指定常量名称是否区分大小写。如果设置为true则不区分大小写;如果设置为false则区分大小写,默认值为false。
<strong>define("COLOR", "red"); //定义一个常量COLOR,值为red echo COLOR."<br>"; //输出常量COLOR的值 </strong>Copy after login
四:变量拓展
可变变量
输出结果为:123<strong>$a="b" $$a="123" //可变变量 echo $b; </strong>Copy after login在字符串中输出变量要使用双引号
$a=50; //echo '我有$a元人民币"; 单引号 echo "我有$a元人民币";Copy after login
在双引号中可以执行的转意字符更多,比如 \n \t \r判断数据类型
$a="-5"; //$a=-5; var_dump($a);Copy after login

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
