Home > php教程 > php手册 > body text

php 用做脚本时的一些技巧

WBOY
Release: 2016-06-06 19:54:59
Original
1068 people have browsed it

-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 等等。用来处理这些数据会方便许多。

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!