The ShellScript PHP conversion method is a bit like the perl cgi method... How is PHPPHP in ShellScript mode so red recently PHP (PersonalHypertextPreprocessor) it seems that it has become the most widely used web page processing language Shell Script in Linux over the past one or two years. how can PHP be so popular recently (Personal Hypertext Preprocessor) it seems that it has become the most widely used web page processing language in Linux/Unix over the past one or two years. its convenience, powerful features and OpenSource features make it gradually eroded to traditional CGI and even microSoft ASP (Active Server Page) in the market, almost all major websites do not use PHP as the basic condition for recruiting talents. PHP does have this qualification so red, for the following reasons: PHP is an OpenSource software that is completely free and can be freely distributed. Therefore, it attracts a lot of people to use it. In addition, it attracts commercial companies to develop better engine and optimization software for it (please reference http://www.zend.com/ ). PHP itself is very easy to understand, simple command syntax, and some basic object oriented processing capabilities, so that new users can learn in the shortest time. PHP provides many functions, including mathematical processing, string processing, network-related functions, various database support, image processing functions, and various types of PHP development for many developers. new features provide excellent scalability. PHP is very easy to combine with Apache. it is used as an Apache module and is quite simple to set and install. it is also because Apache currently occupies 60% of the global market for Web Server, and PHP naturally becomes the best Apache. matching. However, the subject of this talk is not the application of PHP in web design, but the application of PHP in Shell Script. Generally, the Shell Script is about tcsh, bash, perl, or python. I want to talk about using PHP as a Shell Script. PHP execution files are usually compiled into Apache modules as web page processing languages. of course, this is not the case here. Therefore, it is easy to compile as long as the following actions are performed as root: after unlocking the php-3.0.xx.tar.gz cd php configure make compilation, there is an executable file under the php directory named php, copy it to/usr/local/bin. Note: If the file size is too large, you can use the strip command to remove unnecessary information from php, so that the file size will be much smaller. The first program starts to write our first PHP Shell Script program. This example shows "Hello world! ":#! /Usr/local/bin/php-q Note that PHP is originally applied on a webpage, 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 if-q is not added, try again. 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, where" "is a line break character. Note that after saving the program as a file, you must convert its chmod into an executable attribute (chmod + x file name) before executing it. For advanced I usage, sometimes we need to send some parameters during program execution, such as the ls command. the-l parameter can be added later, and PHP Shell Script also supports this usage. There are two special variables: $ argc records the number of input parameters. $ argv [] array parameters are stored in 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 the program is named sum. php3. then, execute sum. php3 1 2 and press enter to print 3. If you want to calculate the parameters and numbers of unspecified numbers, you need to use the special variable $ argc :#! /Usr/local/bin/php-q Assume that the program is named bigsum. php3, bigsum is executed. php3 1 2 3 4 5 press enter to print 15 and execute bigsum. php3 1 2 3 4 5 6 press enter to print 21. Sometimes we need to input data in the program execution, but PHP was originally used for webpage design, and the data input on the webpage is naturally input using FORM, so PHP is used as Shell Script the problem arises. Fortunately, PHP provides the file opening function, while under Linux/Uinx, input (input) you can use the archive method to enable/dev/stdin (stdin indicates standard input). The procedure is as follows :#! /Usr/local/bin/php-q Fgets ($ fp, 100) indicates the file from $ fp (that is, "/dev/stdin ") read 100 bytes of data, and the program will stop waiting for our input. after we press enter, the program will print the information we just entered yes. Although advanced application II can process input, this feature is obviously too simple to handle larger applications. for example, I need a function to process a data stream) in this case, you need to completely 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 wait for you to enter it until you press Ctrl + D to print your input data. we can execute it like this: more filt. php3 | filt. php3 is used to convert filt. the php3 program uses more to show and turn to filt. php3, filt. php3 will continue to accept materials (in fact, it is filt. php3 program code itself), and finally print it out. We can add the HTML filter function :#! /Usr/local/bin/php-q
Http://www.bkjia.com/PHPjc/531741.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/531741.htmlTechArticleShell Script method of PHP how so red recently PHP (Personal Hypertext Preprocessor) seems to have become the most widely used web processing language for Linux/Unix in the past one or two years...