How is PHPPHP in ShellScript mode so red recently, PHP (PersonalHypertextPreprocessor) seems to have become the most widely used web page processing language in Linux/Unix over the past one or two years? With its convenience, powerful functions and OpenSource features, it is gradually eroded to the traditional CGISynt
How can PHP in Shell Script mode be so red recently (Personal Hypertext Preprocessor) seems to have become the most widely used web page processing language in Linux/Unix over the past one or two years? With its convenience, powerful features, and OpenSource features, it is gradually becoming more vulnerable to traditional CGI and even MicroSoft ASP (Active Server Page) markets? Almost all major websites do not use PHP as the basic condition for recruiting talents. PHP is so lucky to have this qualification? The reason is as follows: is PHP an OpenSource software? Completely free? Can be freely distributed? So it attracted a lot of people to use it? And that's why? Attracts commercial companies to develop better engine and optimization software for them (see http://www.zend.com/ ). PHP itself is very easy to understand? Simple command syntax? What are some basic object-oriented processing capabilities? This allows new users to learn in the shortest time. Does PHP provide many functions? It includes mathematical processing, string processing, network-related functions, various database support, image processing functions, and various new functions for PHP for many developers? Excellent scalability. Is PHP very easy to combine with Apache? Used as an Apache module? Is setup quite simple? Because Apache currently occupies 60% of the global market for Web Server? PHP naturally becomes the best combination of Apache. But? Isn't the subject of this talk about the application of PHP in web design? But PHP applications on Shell scripts? Generally, what Shell scripts are known as tcsh, bash, perl, or python? All I want to talk about is using PHP as a Shell Script. PHP execution files are usually compiled into Apache modules as web page processing languages? Of course not here? So it's easy to compile? As long as the root identity for the following action: Unlock the php-3.0.xx.tar.gz cd php configure make after compilation? Is there an executable file in the php directory? File name: php? Copy it to/usr/local/bin. Note? If the file is too big? Can I use the strip command to remove unnecessary information from php? In this way, the file will be much smaller. The first program starts to write our first PHP Shell Script program? This example marks "Hello world! ":#! /Usr/local/bin/php-q Did you notice that PHP was originally used in web applications? So it will certainly send the html header? But here we want to use PHP as a Shell Script? "-Q" means not to send the HEADER? You can try not to add the result of-q. In this example? /Usr/local/bin/php indicates to execute PHP under/usr/local/bin? Because we just installed it here. The echo command will be "Hello, world! "Printed? The "" character is a newline character. After saving this program as an archive? Must its chmod be converted into an executable attribute (chmod + x file name )? Then you can execute it. When advanced I is used, sometimes we need to execute the program? Input some parameters? For example, the ls command? Can the-l parameter be added later? Does PHP Shell Script support this usage? There are two special variables: $ argc records the number of input parameters? $ Argv [] the array parameter contains the parameter content. For example, I want to design a program to calculate the sum of two numbers :#! /Usr/local/bin/php-q Assume that this program is named sum. php3? Run sum. php3 1 2 and press enter to print 3. If you want to calculate the parameter and? Then we need to use the special variable $ argc :#! /Usr/local/bin/php-q Assume that the program is named bigsum. php3? Run bigsum. php3 1 2 3 4 5 and press enter to print 15? Execute bigsum. php3 1 2 3 4 5 6 press enter to print 21. Sometimes we need to input information in program execution? But is PHP originally used for webpage design? The data input on the webpage is naturally in FORM mode? So the question arises when PHP is used as a Shell Script? Fortunately, PHP provides the file opening function? But under Linux/Uinx? Can I use the open file method to complete the input task? What we need to enable is the/dev/stdin device file (stdin indicates standard input )? The program is as follows :#! /Usr/local/bin/php-q Where fgets ($ fp, 100) refers to reading 100 bytes from the $ fp file (that is, "/dev/stdin? When the program runs this line, it will stop waiting for our input? After we enter and press enter? The program will print the information we just entered. Can I process input even if I use advanced II? But is such a function quite simple? Cannot cope with larger applications? For example, I need a function to remove the HTML in a data stream? In this case, you need to fully process the output input and output redirection capabilities? We can first design the program as follows :#! /Usr/local/bin/php-q Assume that this program is named filt. php3? If you directly execute this program? It will always wait for you to enter? It is not until you press Ctrl + D that your input data is printed? We can execute it like this: more filt. php3 | filt. php3 is to show the filt. php3 program with more and turn to the filt. php3 program? Filt. php3 will keep receiving materials (in fact, the filt. php3 program code itself )? Finally, print it out. We can add the HTML filter function :#! /Usr/local/bin/php-q