


Summary of basic syntax knowledge points for getting started with PHP programming, basic syntax for getting started with programming
1. What is php
PHP, or "PHP: Hypertext Preprocessor", is a widely used open source general scripting language, especially suitable for web development and can be embedded in HTML. Its syntax leverages C, Java, and Perl and is easy to learn. The main goal of the language is to allow web developers to quickly write dynamically generated web pages, but PHP can be used for much more than that.
To put it simply, php is a scripting language that can do many things. ① Server-side script ② Command line script ③ Writing desktop program
2. Start php
(1) Download the php interpreter. In fact, under win, the simplest software is wamp. Download it and you will have everything...
(2) It seems that you still need it under win. The mscvr110.dll link library and the vc2012 runtime library can be installed
(3)ide, I shamelessly used phpStorm, I will make it up to you when I get rich, so...
User: newasp License: ===== LICENSE BEGIN ===== 14617-12042010 00001xrVkhnPuM!Bd!vYtgydcusnqt mM!hZWoGg"DprWxZCBwsy8T91O7MRu NVHtrbzv8O9mmoLvtijcHSSE7i5Jr! ===== LICENSE END ====
3. Getting started
(1) Simple output
<?php /** * Created by PhpStorm. * User: LENOVO * Date: 2014/9/28 * Time: 14:51 */ // 输出PHP详细信息 echo phpinfo(); //C:\php-5.6.1-Win32-VC11-x86\php.exe D:\dizzy\php_test\index.php //phpinfo() //PHP Version => 5.6.1 // //System => Windows NT LENOVO-PC 6.1 build 7600 (Windows 7 Ultimate Edition) i586 //Build Date => Sep 24 2014 18:54:12 //Compiler => MSVC11 (Visual C++ 2012) //Architecture => x86 //Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo" //Server API => Command Line Interface
(2) Simple form processing
// 一个简单的html表单 <form action="action.php" method="post"> <p>姓名: <input type="text" name="name" /></p> <p>年龄: <input type="text" name="age" /></p> <p><input type="submit" /></p> </form> // action.php 接收表单数据, 使用超全局变量 %_POST["name"] %_POST["age"] <?php echo htmlspecialchars($_POST['name']); ?> <?php echo (int)$_POST['age']; ?> // 这便是最简单的表单提交,及数据接收
4. Basic Grammar
(1) PHP tag
<?php echo "Hello World!"; // 当文件为纯PHP时,最好在末尾删除PHP结束标记 //?>
(2) Separate from HTML
// 在一对开始和结束之外的内容,都会被PHP解释器忽略。也就是html标签和PHP代码混合的那种,跟jsp,asp一样... <p>This is going to be ignored by PHP and displayed by the browser.</p> <?php echo 'While this is going to be parsed.'; ?> <p>This will also be ignored by PHP and displayed by the browser.</p> // 使用条件,高级分离 <?php if ($expression == true): ?> This will show if the expression is true. <?php else: ?> Otherwise this will show. <?php endif; ?>
(3) Instruction separator, comment
PHP requires a delimiter to end the directive after each statement.
Comments: // or /* ... */ However, */ will match the closest one, remember! Remember!
5. Type
PHP supports 8 primitive data types.
- Four scalar types: boolean (Boolean), integer (integer), float (floating point, double), string (string)
- Two composite types: array (array), object (object)
- Two special types: resource (resource), NULL (no type)
<?php $a_bool = TRUE; // a boolean $a_str = "foo"; // a string $a_str2 = 'foo'; // a string $an_int = 12; // an integer echo gettype($a_bool); // prints out: boolean echo gettype($a_str); // prints out: string // If this is an integer, increment it by four if (is_int($an_int)) { $an_int += 4; } // If $bool is a string, print it out // (does not print out anything) if (is_string($a_bool)) { echo "String: $a_bool"; } ?>
(1) Boolean Boolean type
Can be TRUE or FALSE and is not case sensitive.
Generally, if it is not 0, it is TRUE.
(2) Integer
Integers can be represented in decimal, hexadecimal, octal or binary. The octal number must be preceded by 0 (zero), the hexadecimal number must be preceded by 0x, and the binary number must be preceded by 0b.
If a given number exceeds the range of interger, it will be interpreted as float. The same operation result exceeds the range of integer, and the same is true.
PHP does not have an integer division operator, 1/2 will produce float 0.5. You can cast to integer or use round() for better rounding.
echo (int)2.9; // 输出 2 echo round(2.555, 2) // 输出 2.56 // 决不要将未知的分数强制转换为 integer,这样有时会导致不可预料的结果。 <?php echo (int) ( (0.1+0.7) * 10 ); // 显示 7! ?>
(3) Float floating point type (double)
Floating point type, also called floating point number float, double precision double, real number real.
<?php $a = 1.234; $b = 1.2e3; $c = 7E-10; ?>
(4) String character conversion
A string string is composed of a series of characters, where each character is equivalent to one byte. This means that php can only support 256 character sets and therefore does not support Unicode.
The maximum string size can reach 2GB.
<?php $a = 123; echo '$a'; // 输出 $a echo "$a"; // 输出 123, 转义字符 '\' $str = <<<'EOD' Example of string spanning multiple lines using nowdoc syntax. EOD; ?>
(5) Array array
The array in php is actually an ordered sequence. Mapping is a type that associates values to keys.
Since the values of array elements can also be said to be other arrays, tree structures and multi-dimensional arrays are also allowed.
<?php $array = array( "foo" => "bar", "bar" => "foo", ); // 自PHP 5.4 起 $array = [ "foo" => "bar", "bar" => "foo", ] // key 可以是 integer 或 string 类型 // key 值为可选项, 如果未指定,则使用之前用过最大的integer键名加上1作为新键名 ?> // 要修改某个值,通过其键名给该单元赋一个新值。 // 要删除某个键值对,对其调用 unset() 函数。
When using unset(), please note that the array will not be re-indexed at this time. If you need to rebuild the index, you can use the array_values() function.
why being counted?
(6) Object
<?php class foo{ function do_foo(){ echo "Doing foo."; } } // 用 new 实例化一个类 $f = new foo; $f->do_foo;(7) Resource resource type
Resource resource is a special variable that holds a reference to an external resource. Resources are created and used through specialized functions.
(8) NULL
The special NULL indicates that a variable has no value. The only possible value of type NULL is NULL.
Variables that can be recognized as NULL: ①Assigned to NULL ②Not yet assigned ③Unset
(9) Callback callback type
Since PHP5.4, you can use the callable type to specify the callback type callback.
六、变量
php中变量用一个美元符号 $ 后面跟变量名来表示的。区分大小写。
变量默认总是传值赋值。
<?php $a = 1; // 值传递赋值 $b = $a // 引用赋值 $c = &$a // global 关键字 global ; $GLOBALS
您可能感兴趣的文章:
- 在PHP中检查PHP文件是否有语法错误的方法
- PHP 基本语法格式
- PHP教程 基本语法
- PHP insert语法详解
- PHP语法速查表
- 浅谈PHP语法(1)
- PHP语法自动检查的Vim插件
- php正则表达式的基本语法总结
- 配置php网页显示各种语法错误
- php trim 去除空字符的定义与语法介绍

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment
