Introduction to PHP Programming basic grammar Knowledge Point summary _php Foundation

Source: Internet
Author: User
Tags html form mssql php programming phpinfo lenovo

First, what is PHP

PHP, or "Php:hypertext preprocessor", is a widely used open source general-purpose scripting language, especially for WEB development and embedding HTML. Its syntax uses C, Java, and Perl, and is easy to learn. The primary goal of the language is to allow web developers to quickly write dynamically generated Web pages, but PHP is far more useful than that.

Simply put, PHP is a scripting language that can do a lot of things. ① server-side Script ② command line script ③ write desktop program

Second, start PHP

(1) Download PHP interpreter, actually win below, the simplest or wamp this software, download down everything has ...

(2) win below seemingly also need, mscvr110.dll this link library, vc2012 run the library, install can

(3) The IDE, shameless use of the phpstorm, and so brother Rich must give you back, so ...

user:newasp
License:
===== License
===== 14617-12042010 Mm!hzwogg "Dprwxzcbwsy8t91o7mru
nvhtrbzv8o9mmolvtijchsse7i5jr!
===== LICENSE End = =

Iii. Introductory Guide

(1) Simple output

<?php
/**
 * Created by Phpstorm.
 * User:lenovo
 * DATE:2014/9/28
 * time:14:51
///output PHP details
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 2014 18:54:12
//compiler => MSVC11 (Visual C + +)
//architecture =>-x86//configure comman
D => 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

A simple HTML form
<form action= "action.php" method= "POST" >
  <p> Name: <input type= "text" name= "name" /></p>
  <p> Ages: <input type= "text" name= "age"/></p> <p><input type=
  " Submit "/></p>
</form>
 
//action.php Receive form data, use Super global variable
%_post[" name "
%_post[" age "]
<?php Echo htmlspecialchars ($_post[' name ');?>
<?php Echo (int) $_post[' age ';?>
// This is the simplest form submission, and data reception

Four, the basic grammar

(1) PHP tags

<?php
 
echo "Hello world!";
 
When the file is pure PHP, it is best to remove the PHP end tag at the end
//?>

(2) separating from HTML

Content beyond the start and end of a pair will be ignored by the PHP interpreter. Which is the HTML tag and the PHP code mix, like jsp,asp ...
<p>this is going to being ignored by PHP and displayed by the browser.</p>
<?php Echo ' While this is going To be parsed. '; ?>
<p>this would also be ignored
 
by PHP and displayed by the browser.</p>//usage conditions, advanced separation
<?php if ($expression = = true):?> This'll show
  if the expression is true.
<?php Else:?> Otherwise this'll show
  .
<?php endif;?>

(3) Instruction separator, note

PHP needs to end the instruction with a delimiter after each statement.

Note://////* ... * * but, * * will match the nearest one, remember! Remember!

Five, type

PHP supports 8 of original data types.

    • Four scalar types: Boolean (Boolean), Integer (integer), float (floating point type, double), string (string)
    • Two composite types: Array (array), Object (objects)
    • 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 =;   An integer
 
echo GetType ($a _bool);//Prints Out:boolean
echo GetType ($a _str);//Prints out:string
 
//If This is a 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 stri NG: $a _bool ";
}
? >

(1) Boolean type

can be true or false, case-insensitive.

The general is not 0, that is true.

(2) Integer integer type

Integral types can be represented by decimal, hexadecimal, octal, or binary. Octal must be preceded by 0 (0), Hex plus 0x, binary plus 0b.

If a given number exceeds the range of Interger, it will be interpreted as float. The same is true of the result of the operation exceeding the integer range.

PHP does not have an integer operator, 1/2 will produce float 0.5. You can cast to integer or use round () for better rounding.

echo (int) 2.9; Output 2
echo round (2.555, 2)//output 2.56

//Never cast an unknown fraction to integer, which sometimes leads to unpredictable results.
<?php
Echo (int) (0.1+0.7) * 10);//show 7!
? >

(3) Float floating-point type (double)

Floating-point type, also known as floating point float, double-precision double, real reals.

<?php
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
? >

(4) String character transfer

A string that consists of a series of characters, each of which is equal to one byte. This means that PHP can only support 256 character sets, so Unicode is not supported.

The string can be up to 2GB max.

<?php
$a = 123;
echo ' $a '; Output $a
echo "$a";//output 123, escape character ' \
 
' $str = <<< ' EOD '
Example of string
spanning multiple lines
using Nowdoc syntax.
EOD;
 
? >

(5) Array arrays

The array in PHP is actually an ordered sequence. A mapping is a type that associates values to the keys.

Because the value of an array element can also be said to be a different array, the tree structure and multidimensional array are allowed.

<?php
$array = Array (
  "foo" => "Bar",
  "bar" => "foo"
);
 
From PHP 5.4
$array = [
  "foo" => "Bar",
  "bar" => "foo",
]
//Key can be an integer or string type
The key value is optional, and if unspecified, use the largest integer key name plus 1 for the new key name
?>
 
//To modify a value and assign a new value to the cell by its key name.
//To delete a key-value pair, call the unset () function on it.

Use unset () to note that the array does not rebuild the index at this time. You need to rebuild the index, you can use the Array_values () function.

Total array Count: Using the Count () function

(6) Object

<?php
class foo{
  function Do_foo () {
    echo "doing foo.";
  }
}
Instantiate a class with 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

A special null indicates that a variable has no value. The only possible value for a null type is NULL.

A variable that can be considered null: ① is assigned to Null② has not been assigned ③ been unset

(9) Callback callback type

You can use the callable type to specify the callback type callback since PHP5.4.

Six, variable

Variables in PHP are represented by a dollar sign, followed by a variable name. Case sensitive.

Variable values are always assigned by default.

<?php
 
$a = 1;
Value Pass Assignment 
$b = $a
//reference assignment
$c = & $a
 
/global keyword
global; $GLOBALS


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.