Home  >  Article  >  Backend Development  >  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

WBOY
WBOYOriginal
2016-07-12 08:59:541084browse

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

<&#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

(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;>
// 这便是最简单的表单提交,及数据接收

4. Basic Grammar

(1) PHP tag

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

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

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

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

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

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

(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() 函数。

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


您可能感兴趣的文章:

  • 在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:
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