Table of Contents
Summary of basic syntax knowledge points for getting started with PHP programming, basic syntax for getting started with programming
您可能感兴趣的文章:
Home Backend Development PHP Tutorial Summary of basic syntax knowledge points for getting started with PHP programming, basic syntax for getting started with programming_PHP tutorial

Summary of basic syntax knowledge points for getting started with PHP programming, basic syntax for getting started with programming_PHP tutorial

Jul 12, 2016 am 08:59 AM
php grammar

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 ====
Copy after login

3. Getting started

(1) Simple output

<&#63;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
Copy after login

(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"]
<&#63;php echo htmlspecialchars($_POST['name']); &#63;>
<&#63;php echo (int)$_POST['age']; &#63;>
// 这便是最简单的表单提交,及数据接收

Copy after login

4. Basic Grammar

(1) PHP tag

<&#63;php
 
echo "Hello World!";
 
// 当文件为纯PHP时,最好在末尾删除PHP结束标记
//&#63;>
Copy after login

(2) Separate from HTML

// 在一对开始和结束之外的内容,都会被PHP解释器忽略。也就是html标签和PHP代码混合的那种,跟jsp,asp一样...
<p>This is going to be ignored by PHP and displayed by the browser.</p>
<&#63;php echo 'While this is going to be parsed.'; &#63;>
<p>This will also be ignored by PHP and displayed by the browser.</p>
 
// 使用条件,高级分离
<&#63;php if ($expression == true): &#63;>
  This will show if the expression is true.
<&#63;php else: &#63;>
  Otherwise this will show.
<&#63;php endif; &#63;>
Copy after login

(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)
<&#63;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";
}
&#63;>
Copy after login

(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,这样有时会导致不可预料的结果。
<&#63;php
echo (int) ( (0.1+0.7) * 10 ); // 显示 7!
&#63;>

Copy after login

(3) Float floating point type (double)

Floating point type, also called floating point number float, double precision double, real number real.

<&#63;php
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
&#63;>
Copy after login

(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.

<&#63;php
$a = 123;
echo '$a'; // 输出 $a
echo "$a"; // 输出 123, 转义字符 '\'
 
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
 
&#63;>
Copy after login

(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.

<&#63;php
$array = array(
  "foo" => "bar",
  "bar" => "foo",
);
 
// 自PHP 5.4 起
$array = [
  "foo" => "bar",
  "bar" => "foo",
]
// key 可以是 integer 或 string 类型
// key 值为可选项, 如果未指定,则使用之前用过最大的integer键名加上1作为新键名
&#63;>
 
// 要修改某个值,通过其键名给该单元赋一个新值。
// 要删除某个键值对,对其调用 unset() 函数。
Copy after login

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

<&#63;php
class foo{
  function do_foo(){
    echo "Doing foo.";
  }
}
// 用 new 实例化一个类
$f = new foo;
$f->do_foo;
Copy after login
(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中变量用一个美元符号 $ 后面跟变量名来表示的。区分大小写。

变量默认总是传值赋值。

<&#63;php
 
$a = 1;
// 值传递赋值 
$b = $a
// 引用赋值
$c = &$a
 
// global 关键字
global ; $GLOBALS
Copy after login


您可能感兴趣的文章:

  • 在PHP中检查PHP文件是否有语法错误的方法
  • PHP 基本语法格式
  • PHP教程 基本语法
  • PHP insert语法详解
  • PHP语法速查表
  • 浅谈PHP语法(1)
  • PHP语法自动检查的Vim插件
  • php正则表达式的基本语法总结
  • 配置php网页显示各种语法错误
  • php trim 去除空字符的定义与语法介绍

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1096144.htmlTechArticlePHP编程入门的基本语法知识点总结,编程入门基本语法 一、何为php PHP,即“PHP: Hypertext Preprocessor”,是一种被广泛应用的开源通用脚本语...
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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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
1666
14
PHP Tutorial
1273
29
C# Tutorial
1254
24
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.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles