


Shell Script PHP Why is PHP so popular? Recently, PHP (Personal Hypertext Preprocessor) seems to have become the most widely used web page processing language on Linux/Unix in the past two years. Its convenience, powerful functions and OpenSource features make it It is gradually eroding the market of traditional CGI and even MicroSoft ASP (Active Server Page). Almost all major websites recruit talents with PHP as a basic condition. PHP does have this qualification to become so popular. The reasons are as follows: PHP is OpenSource software, completely free and can be freely distributed. Therefore, it has attracted a lot of people to use it. Because of this, it has attracted commercial companies to develop it better. Engine and optimization software (please refer to http://www.zend.com/). PHP itself is very simple and easy to understand, with simple command syntax and some basic object-oriented processing capabilities, allowing novices to learn it in the shortest time. PHP provides quite a lot of functions, including mathematical processing, string processing, network-related functions, support for various databases, and image processing functions. A large number of developers are developing various new functions and expansions for PHP. Sex is excellent. PHP is very easy to combine with Apache. It can be used as a module of Apache. The configuration and installation are quite simple. And because Apache currently accounts for 60% of the global Web Server market, PHP naturally becomes the best match for Apache. However, the topic I want to talk about this time is not the application of PHP in web design, but the application of PHP in Shell Script. The commonly known Shell Script is about tcsh, bash, perl or python. What I want to talk about What we are talking about is using PHP as a Shell Script. Installation of PHP executable file Generally, PHP as a web page processing language needs to be compiled into an Apache module. Of course, this is not done here, so compilation is very simple. Just perform the following actions as root: Unzip php-3.0.xx. tar.gz cd php configure make After compilation, there will be an executable file in the php directory. The file name is php. Just copy it to /usr/local/bin. Note that if the file is too large, you can use the strip command to remove unnecessary information in PHP, so that the file will be much smaller. The first program starts writing our first PHP Shell Script program. This example prints "Hello world!": #!/usr/local/bin/php -q echo "Hello, world !"; ?> Note that PHP was originally used in web applications , so it will send the HTML HEADER by default, but here we are using PHP as a Shell Script. "-q" means not to send the HEADER. You can try the display result without adding -q. In this example, /usr/local/bin/php means to execute PHP under /usr/local/bin/ because we just installed it there. The echo command prints "Hello, world!", in which the "" character is a newline character. Note that after saving this program into a file, you must chmod it to become executable (chmod +x file name) before it can be executed. Advanced use of I Sometimes we need to send some parameters when the program is executed. For example, the ls command can be followed by the -l parameter. PHP Shell Script also supports this usage. There are two special variables: $ argc records the number of parameters sent later, and the $argv[] array parameter stores the content of the parameters. For example, I want to design a program that calculates the sum of two numbers: #!/usr/local/bin/php -q $sum=0; $sum=$sum+$argv[1]+$argv[2]; echo $sum; ?> Assume this program is named sum.php3, then execute sum.php3 1 2 Press enter 3 will be printed. If you want to calculate the sum of an unspecified number of parameters, you have to use the special variable $argc: #!/usr/local/bin/php -q $sum=0; for ($t=1;$t Assume this program is named bigsum.php3, then Execute bigsum.php3 1 2 3 4 5 and press enter, and 15 will be printed. Execute bigsum.php3 1 2 3 4 5 6 and press enter, and 21 will be printed. Sometimes we need to input data during program execution, but PHP was originally used for web design, and the data input on the web page is naturally entered using FORM, so this problem arises when using PHP as a Shell Script. Okay PHP provides a file opening function, but under Linux/Uinx, input can be done by opening a file. What we want to open is the device file /dev/stdin (stdin is means standard input), the program is as follows: #!/usr/local/bin/php -q $fp=fopen("/dev/stdin","r"); $inputstr=fgets($fp,100); fclose($fp); echo " ---------------------- "; echo $inputstr; ?> where fgets($fp,100) refers to the file $fp (that is, "/dev/stdin" ) to read 100 bytes of data. When the program reaches this line, it will stop and wait for our input. When we finish inputting and press enter, the program will print out the data we just entered.Advanced Use II Although it can already handle input, this function is obviously still too simple and cannot cope with larger applications. For example, I need a function to remove HTML from a series of data streams. At this time We need the ability to completely handle output and input steering. We can first design the program as follows: #!/usr/local/bin/php -q $fp=fopen("/dev/stdin","r"); while(!feof($fp)) { $c=fgetc($fp); $inputstr=$inputstr.$c; }; fclose($fp); echo $inputstr; ?> Assume that this program is named filt.php3. If you execute this program directly, It will wait for your input until you press Ctrl+D before printing out your input data. We can execute it like this: more filt.php3 | filt.php3 This method is to replace the filt.php3 program Use more to show and redirect to the filt.php3 program. filt.php3 will continue to receive data (actually the filt.php3 program code itself) and finally print it out. We can add the function of filtering HTML: #!/usr/local/bin/php -q $fp=fopen("/dev/stdin","r"); while(!feof($fp)) { $c=fgetc($fp); $inputstr=$inputstr.$c; }; fclose($fp); $inputstr=ereg_replace("

技嘉的主板怎么设置键盘开机首先,要支持键盘开机,一定是PS2键盘!!设置步骤如下:第一步:开机按Del或者F2进入bios,到bios的Advanced(高级)模式普通主板默认进入主板的EZ(简易)模式,需要按F7切换到高级模式,ROG系列主板默认进入bios的高级模式(我们用简体中文来示范)第二步:选择到——【高级】——【高级电源管理(APM)】第三步:找到选项【由PS2键盘唤醒】第四步:这个选项默认是Disabled(关闭)的,下拉之后可以看到三种不同的设置选择,分别是按【空格键】开机、按组

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

1.处理器在选择电脑配置时,处理器是至关重要的组件之一。对于玩CS这样的游戏来说,处理器的性能直接影响游戏的流畅度和反应速度。推荐选择IntelCorei5或i7系列的处理器,因为它们具有强大的多核处理能力和高频率,可以轻松应对CS的高要求。2.显卡显卡是游戏性能的重要因素之一。对于射击游戏如CS而言,显卡的性能直接影响游戏画面的清晰度和流畅度。建议选择NVIDIAGeForceGTX系列或AMDRadeonRX系列的显卡,它们具备出色的图形处理能力和高帧率输出,能够提供更好的游戏体验3.内存电

主板上SPDIFOUT连接线序最近我遇到了一个问题,就是关于电线的接线顺序。我上网查了一下,有些资料说1、2、4对应的是out、+5V、接地;而另一些资料则说1、2、4对应的是out、接地、+5V。最好的办法是查看你的主板说明书,如果找不到说明书,你可以使用万用表进行测量。首先找到接地,然后就可以确定其他的接线顺序了。主板vdg怎么接线连接主板的VDG接线时,您需要将VGA连接线的一端插入显示器的VGA接口,另一端插入电脑的显卡VGA接口。请注意,不要将其插入主板的VGA接口。完成连接后,您可以

广联达软件是一家专注于建筑信息化领域的软件公司,其产品被广泛应用于建筑设计、施工、运营等各个环节。由于广联达软件功能复杂、数据量大,对电脑的配置要求较高。本文将从多个方面详细阐述广联达软件的电脑配置推荐,以帮助读者选择适合的电脑配置处理器广联达软件在进行建筑设计、模拟等操作时,需要进行大量的数据计算和处理,因此对处理器的要求较高。推荐选择多核心、高主频的处理器,如英特尔i7系列或AMDRyzen系列。这些处理器具有较强的计算能力和多线程处理能力,能够更好地满足广联达软件的需求。内存内存是影响计算

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

去除方法:1、使用substr_replace()函数将首位数字替换为空字符串即可,语法“substr_replace($num,"",0,1)”;2、用substr截取从第二位数字开始的全部字符即可,语法“substr($num,1)”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
