Home  >  Article  >  php教程  >  php 用做脚本时的一些技巧

php 用做脚本时的一些技巧

WBOY
WBOYOriginal
2016-06-06 19:54:591067browse

-r 参数可以直接执行一段代码,不需要 ?php 例如 php -r 'phpinfo();' -R 参数可以对标准输入的每一行执行一段代码。会有两个变量,$argi 是行号, $argn 是当前行内容。 例如 ls | php -R 'echo "$argi/t$argn/n";' -B,-E 分别表示在整个处理输入的开始和

-r 参数可以直接执行一段代码,不需要 例如 php -r 'phpinfo();'

-R 参数可以对标准输入的每一行执行一段代码。会有两个变量,$argi 是行号, $argn 是当前行内容。
例如 ls | php -R  'echo "$argi/t$argn/n";'

-B,-E 分别表示在整个处理输入的开始和结束时执行的脚本。
比如 ls | php -R  'echo "$argi/t$argn/n";' -B 'echo "Begin/n";' -E 'echo "End/n";'
结果会是

Begin
1       a.txt
2       b.txt
3       c.txt
...
End

更多参数可以看 man php 。

php 用在脚本里有啥好处呢?php 带了很多 web 应用常用的函数。比如转义 html ,url 等等。用来处理这些数据会方便许多。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php与Ajax实例Next article:国外主流PHP框架比较