Basic grammar knowledge points for getting started with PHP programming, basic grammar _php tutorials for getting started with programming

Source: Internet
Author: User
Tags getting started with php phpinfo

Basic grammar knowledge points for getting started with PHP programming, basic syntax for getting started with programming


First, what is PHP

PHP, or "Php:hypertext preprocessor", is an open-source universal scripting language that is widely used, especially for WEB development and embedded in HTML. Its syntax takes advantage of 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 is far more useful than that.

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

Second, start PHP

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

(2) win below seems to need, mscvr110.dll this link library, vc2012 run library, installation can

(3) IDE, shameless use of the phpstorm, and so the elder brother has the money to be sure to give you back, so ...

user:newasplicense:===== LICENSE BEGIN =====14617-1204201000001xrvkhnpum!bd!vytgydcusnqtmm!hzwogg " dprwxzcbwsy8t91o7mrunvhtrbzv8o9mmolvtijchsse7i5jr!===== LICENSE END = =

Third, the introduction of guidance

(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 18:54:12//compile R = MSVC11 (Visual C + +)//architecture = x86//configure Command = Cscript/nologo configure.js "--enable-s Napshot-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//action.php receive form data, using a Hyper 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

Iv. 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 that is outside the beginning and end of a pair will be ignored by the PHP interpreter. That is, the HTML tag and PHP code mix of the kind, like jsp,asp ...

This was going to being ignored by PHP and displayed by the browser.

<?php Echo ' While the going to be parsed. '; ?>

This would also is ignored by PHP and displayed by the browser.

Use condition, advanced detach <?php if ($expression = = true):?> This would show if the expression is true.<?php else:? > otherwise this would show.<?php endif;?>

(3) Instruction separator, comment

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

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

Five, type

PHP supports 8 types of raw data.

    • Four scalar types: Boolean (Boolean), Integer (int), float (floating-point, double), string (string)
    • Two composite types: Array (array), 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 = n;   An integer echo GetType ($a _bool); Prints Out:booleanecho GetType ($a _str); Prints out:string//If this is a integer, increment it by Fourif (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, case insensitive.

is generally not 0, which is true.

(2) Integer integer type

Integer types can be expressed in decimal, hexadecimal, octal, or binary notation. Octal must be preceded by 0 (0), hexadecimal plus 0x, binary plus 0b.

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

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

echo (int) 2.9; Output 2echo round (2.555, 2)//output 2.56//never cast an unknown fraction to an integer, which can sometimes lead to unpredictable results. <?phpecho (int) ((0.1+0.7) * 10); Show 7!? >

(3) Float float type (double)

Float, also called floating-point float, double precision, real real.

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

(4) String character Goto

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

<?php$a = 123;echo ' $a '; Output $aecho "$a"; Output 123, escape character ' \ ' $str = <<< ' EOD ' Example of stringspanning multiple linesusing nowdoc syntax. EOD;?>

(5) Array arrays

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

Because the values of the array elements can also be said to be additional arrays, the tree structure and multidimensional arrays are also allowed.

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

Use Unset () to be aware that the array does not rebuild the index at this time. To rebuild the index, you can use the Array_values () function.

Total number of array calculations: using the count () function

(6) Object objects

<?phpclass 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.

Variable that can be identified as null: ① is assigned a value of Null② has not been assigned ③ is unset

(9) Callback callback type

From PHP5.4, you can use the callable type to specify the callback type callback.

Vi. variables

Variables in PHP are represented by a dollar sign followed by a variable name. is case sensitive.

Variables are always assigned values by default.

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


Articles you may be interested in:

    • How to check PHP files for syntax errors in PHP
    • PHP Basic Syntax format
    • PHP Tutorial Basic syntax
    • PHP Insert Syntax detailed
    • PHP Syntax Quick Check table
    • Elementary Introduction to PHP Syntax (1)
    • The Vim plugin for automatic PHP grammar checking
    • Summary of basic syntax for PHP regular expressions
    • Configure PHP Web page to display various syntax errors
    • PHP trim removal null character definition and syntax introduction

http://www.bkjia.com/PHPjc/1096144.html www.bkjia.com true http://www.bkjia.com/PHPjc/1096144.html techarticle PHP Programming Primer Basic Grammar Knowledge point Summary, Programming Primer Basic Syntax One, what is PHP php, that is, "Php:hypertext preprocessor", is a widely used open-source universal scripting language ...

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