Judging teacher PHP Devil Special Training Note (1)

Source: Internet
Author: User

This course personal development environment may consider using Ubuntu, recommending Sublime and phpstorm as the development environment.
One of the major features of PHP is: scripting language, do not compile, you can run after writing it?
However, it is not .....
PHP code must have a "mother" to run. The most straightforward is the "PHP" executable program that we compiled.
This class was put in the/usr/local/php/bin/php.

Second, PHP three mode of operation

Let's start by creating a file named xz1024. Why not add suffixes? You see the course yourself, the teacher when the lecture is so wayward, I also follow wayward ...

<?  ' My name is xz1024 '. Php_eol;? >//If the file has only PHP code, you can not add the seal symbol

1,/usr/local/php/bin/php followed by a PHP file

Run the above file:/usr/local/php/bin/php xz1024
2,/usr/local/php/bin/php-r "here directly write the PHP code"

Run the above file:/usr/local/php/bin/php-r ' echo ' My name is xz1024,18 ";

3. Create a file and write it on the first line (we use these lessons
#! /usr/local/php/bin/php
And then write down the code.

Let's create a file called God.

# ! /usr/local/php/bin/php<? PHP     Echo "I am God". Php_eol ;? >

Then, on the command line./god. Enter, the file does not seem to execute.

Command line under $ chmod + x God

OK, we'll come again./god

  

and copy it to the/usr/local/bin directory.
sudo cp god/usr/local/bin (make sure this directory is in your environment variable)

Third, how to get the parameters.

Maybe a lot of students know how to get get parameters or post parameters in Web pages? But now there's a Web page for wood?
Two global variables $argc and $argv appear, the former is the number of parameters (own one), the latter is the parameter, it is an array.

Now let's open the god file for CP into/usr/local/bin:

    

Four, we do a small practical Walkthrough:

Requirement: When I execute God, if there are no parameters, nothing is displayed. If there is an argument, and the second argument is-V, the following character is printed: God version is 1.0;

# !/usr/local/php/bin/php<? PHP     $result = ";     if ($argc >= 2) {     $argv$result = ' God version is 1.0 ';    }     echo$result;     Echo Php_eol;

Results:

  

If you are a novice, please check the manual to extend the knowledge point:
1. What is Echo?

   Echo - outputs one or more strings. Usage:void echo ( string $arg1 [, string $... ])  

Echo is not a function (it is a language structure), so you do not have to use parentheses to indicate arguments, single quotes, double quotes. Echo (unlike other language constructs) does not behave like a function, so it is not always possible to use the context of a function. Also, if you want to Pass multiple arguments to echo, you cannot use parentheses.

  Other references:

    • Print -Output string
    • printf () -Output formatted string
    • Flush () -Refresh the output buffer

2, the definition of PHP variables:

Variables in PHP are represented by a dollar sign followed by a variable name. Variable names are case-sensitive.

The variable name follows the same rules as other tags in PHP. A valid variable name begins with a letter or underscore, followed by any number of letters, numbers, or underscores.


3, Php_eol:

Line break

UNIX series with \ n

Windows series with \ r \ n

Mac with \ r

PHP can be replaced with Php_eol to improve code-level portability

4. PHP Array:

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

 You can use the array () language structure to create a new array. It accepts any number of key (key) = = values (value) pairs separated by commas.

key =    value     , ...      VALUES (value   ) can be any  type of value   
For more information please refer to the manual www.php.net

5, $ARGC and $ARGV

  $ARGC- The number of arguments passed to the script. Contains the number of arguments that are passed to the current script when run on the command line . The file name of the script is always passed as a parameter to the current script, so $argc the minimum value is 1.

<? PHP Var_dump ($argc);

  $argv-An array of arguments passed to the script that contains the arguments passed to the current script when run on the command line . The first parameter is always the file name of the current script, so it $argv[0] is the script file name.

<? PHP Var_dump ($argv);

7. Condition judgment if () {}

This will not write, if not, really need to look at the basis.

Copyright NOTICE: NOTE-taker fugitive pawns love freedom, advocating sharing. But this note stems from www.jtthink.com (programmer in the awkward way) judging teacher's "PHP Devil Training First stage." This study note pawn in the blog Park debut, if need to reprint please respect the teacher Labor, retain judging teacher attribution and course source address.

Next Lesson: Judging teacher PHP Devil Special Training Note (2)

Judging teacher PHP Devil Special Training Note (1)

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.