pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      1. <legend id='xzqpi'><style id='xzqpi'><dir id='xzqpi'><q id='xzqpi'></q></dir></style></legend>
      2. <small id='xzqpi'></small><noframes id='xzqpi'>

        • <bdo id='xzqpi'></bdo><ul id='xzqpi'></ul>
      3. <i id='xzqpi'><tr id='xzqpi'><dt id='xzqpi'><q id='xzqpi'><span id='xzqpi'><b id='xzqpi'><form id='xzqpi'><ins id='xzqpi'></ins><ul id='xzqpi'></ul><sub id='xzqpi'></sub></form><legend id='xzqpi'></legend><bdo id='xzqpi'><pre id='xzqpi'><center id='xzqpi'></center></pre></bdo></b><th id='xzqpi'></th></span></q></dt></tr></i><div class="xoragmv" id='xzqpi'><tfoot id='xzqpi'></tfoot><dl id='xzqpi'><fieldset id='xzqpi'></fieldset></dl></div>

        <tfoot id='xzqpi'></tfoot>

        如何從命令行執(zhí)行 PHP 代碼?

        How can I execute PHP code from the command line?(如何從命令行執(zhí)行 PHP 代碼?)

          • <legend id='19UKf'><style id='19UKf'><dir id='19UKf'><q id='19UKf'></q></dir></style></legend>
                <tbody id='19UKf'></tbody>
              <tfoot id='19UKf'></tfoot>

              • <bdo id='19UKf'></bdo><ul id='19UKf'></ul>

                <small id='19UKf'></small><noframes id='19UKf'>

              • <i id='19UKf'><tr id='19UKf'><dt id='19UKf'><q id='19UKf'><span id='19UKf'><b id='19UKf'><form id='19UKf'><ins id='19UKf'></ins><ul id='19UKf'></ul><sub id='19UKf'></sub></form><legend id='19UKf'></legend><bdo id='19UKf'><pre id='19UKf'><center id='19UKf'></center></pre></bdo></b><th id='19UKf'></th></span></q></dt></tr></i><div class="ldc3avx" id='19UKf'><tfoot id='19UKf'></tfoot><dl id='19UKf'><fieldset id='19UKf'></fieldset></dl></div>
                  本文介紹了如何從命令行執(zhí)行 PHP 代碼?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我想直接使用命令行執(zhí)行一個像 if(function_exists("my_func")) echo 'function exists'; 這樣的 PHP 語句,而不必使用單獨的 PHP 文件.

                  怎么可能?

                  解決方案

                  如果您打算在命令行中執(zhí)行 PHP,我建議您安裝 phpsh,一個不錯的 PHP shell.它更有趣.

                  無論如何,php 命令提供了兩個從命令行執(zhí)行代碼的開關(guān):

                  -r 運行 PHP <代碼>不使用腳本標(biāo)簽 <?..?>-R<代碼>運行 PHP <代碼>對于每條輸入線

                  您可以像這樣使用 php-r 開關(guān):

                  php -r 'echo function_exists("foo") ?是":不";'

                  上面的 PHP 命令應(yīng)該 output noreturns 0 如您所見:

                  <預(yù)><代碼>>>>php -r 'echo function_exists("foo") ?是":不";'不>>>回聲 $?# 打印上一條命令的返回值0

                  另一個有趣的開關(guān)是php -a:

                  -a 作為交互式 shell 運行

                  與phpsh相比,它有點蹩腳,但如果你不這樣做想要安裝 由 Facebook 制作的很棒的 PHP 交互式 shell 以獲取選項卡完成、歷史記錄等,然后像這樣使用-a:

                  <預(yù)><代碼>>>>php -a交互式外殼php >echo function_exists(foo") ?是":不";不php >

                  如果它在你的盒子上不起作用就像在我的盒子上一樣es(在 Ubuntu 和 Arch Linux),那么可能是您的 PHP 設(shè)置模糊或損壞.如果你運行這個命令:

                  php -i |grep'API'

                  應(yīng)該看到:

                  服務(wù)器 API =>命令行界面

                  如果您不這樣做,這意味著也許另一個命令將提供 CLI SAPI.試試 php-cli;也許它是您操作系統(tǒng)中可用的包或命令.

                  如果您看到您的 php 命令使用 CLI(命令行界面)SAPI(服務(wù)器 API),然后運行 ??php -h |grep 代碼 找出哪個瘋狂的開關(guān) - 因為這已經(jīng)一年沒有改變了 - 允許在您的版本/設(shè)置中運行代碼.

                  另外幾個例子,只是為了確保它適用于我的盒子:

                  <預(yù)><代碼>>>>php -r 'echo function_exists("sg_load") ?是":不";'不>>>php -r 'echo function_exists("print_r") ?是":不";'是的

                  另外,請注意擴(kuò)展程序可能加載到 CLI 而不是 CGI 或 Apache SAPI.很可能幾個 PHP SAPI 使用不同的 php.ini 文件,例如 /etc/php/cli/php.ini/etc/php/cgi/php.ini/etc/php/apache/php.ini 在 Gentoo Linux 框.找出哪個 ini 文件與 php -i | 一起使用grep ini.

                  I would like to execute a single PHP statement like if(function_exists("my_func")) echo 'function exists'; directly with the command line without having to use a separate PHP file.

                  How is it possible?

                  解決方案

                  If you're going to do PHP in the command line, I recommend you install phpsh, a decent PHP shell. It's a lot more fun.

                  Anyway, the php command offers two switches to execute code from the command line:

                  -r <code>        Run PHP <code> without using script tags <?..?>
                  -R <code>        Run PHP <code> for every input line
                  

                  You can use php's -r switch as such:

                  php -r 'echo function_exists("foo") ? "yes" : "no";'
                  

                  The above PHP command above should output no and returns 0 as you can see:

                  >>> php -r 'echo function_exists("foo") ? "yes" : "no";'
                  no
                  >>> echo $? # print the return value of the previous command
                  0
                  

                  Another funny switch is php -a:

                  -a               Run as interactive shell
                  

                  It's sort of lame compared to phpsh, but if you don't want to install the awesome interactive shell for PHP made by Facebook to get tab completion, history, and so on, then use -a as such:

                  >>> php -a
                  Interactive shell
                  
                  php > echo function_exists("foo") ? "yes" : "no";
                  no
                  php >
                  

                  If it doesn't work on your box like on my boxes (tested on Ubuntu and Arch Linux), then probably your PHP setup is fuzzy or broken. If you run this command:

                  php -i | grep 'API'
                  

                  You should see:

                  Server API => Command Line Interface
                  

                  If you don't, this means that maybe another command will provides the CLI SAPI. Try php-cli; maybe it's a package or a command available in your OS.

                  If you do see that your php command uses the CLI (command-line interface) SAPI (Server API), then run php -h | grep code to find out which crazy switch - as this hasn't changed for year- allows to run code in your version/setup.

                  Another couple of examples, just to make sure it works on my boxes:

                  >>> php -r 'echo function_exists("sg_load") ? "yes" : "no";'
                  no
                  >>> php -r 'echo function_exists("print_r") ? "yes" : "no";'
                  yes
                  

                  Also, note that it is possible that an extension is loaded in the CLI and not in the CGI or Apache SAPI. It is likely that several PHP SAPIs use different php.ini files, e.g., /etc/php/cli/php.ini vs. /etc/php/cgi/php.ini vs. /etc/php/apache/php.ini on a Gentoo Linux box. Find out which ini file is used with php -i | grep ini.

                  這篇關(guān)于如何從命令行執(zhí)行 PHP 代碼?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)
                • <legend id='9SWcW'><style id='9SWcW'><dir id='9SWcW'><q id='9SWcW'></q></dir></style></legend>

                    • <small id='9SWcW'></small><noframes id='9SWcW'>

                          <tbody id='9SWcW'></tbody>
                        <i id='9SWcW'><tr id='9SWcW'><dt id='9SWcW'><q id='9SWcW'><span id='9SWcW'><b id='9SWcW'><form id='9SWcW'><ins id='9SWcW'></ins><ul id='9SWcW'></ul><sub id='9SWcW'></sub></form><legend id='9SWcW'></legend><bdo id='9SWcW'><pre id='9SWcW'><center id='9SWcW'></center></pre></bdo></b><th id='9SWcW'></th></span></q></dt></tr></i><div class="ablgjaq" id='9SWcW'><tfoot id='9SWcW'></tfoot><dl id='9SWcW'><fieldset id='9SWcW'></fieldset></dl></div>
                        • <bdo id='9SWcW'></bdo><ul id='9SWcW'></ul>
                          1. <tfoot id='9SWcW'></tfoot>

                            主站蜘蛛池模板: 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 经济师考试_2025中级经济师报名时间_报名入口_考试时间_华课网校经济师培训网站 | 防爆电机-高压防爆电机-ybx4电动机厂家-河南省南洋防爆电机有限公司 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 首页-恒温恒湿试验箱_恒温恒湿箱_高低温试验箱_高低温交变湿热试验箱_苏州正合 | 智能垃圾箱|垃圾房|垃圾分类亭|垃圾分类箱专业生产厂家定做-宿迁市传宇环保设备有限公司 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 进口消泡剂-道康宁消泡剂-陶氏消泡剂-大洋消泡剂 | 隆众资讯-首页_大宗商品资讯_价格走势_市场行情 | 氧氮氢联合测定仪-联测仪-氧氮氢元素分析仪-江苏品彦光电 | 湿地保护| 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 实战IT培训机构_IT培训班选大学生IT技术培训中心_中公优就业 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 金联宇电缆总代理-金联宇集团-广东金联宇电缆实业有限公司 | 大功率金属激光焊接机价格_不锈钢汽车配件|光纤自动激光焊接机设备-东莞市正信激光科技有限公司 定制奶茶纸杯_定制豆浆杯_广东纸杯厂_[绿保佳]一家专业生产纸杯碗的厂家 | 布袋除尘器-单机除尘器-脉冲除尘器-泊头市兴天环保设备有限公司 布袋除尘器|除尘器设备|除尘布袋|除尘设备_诺和环保设备 | 防锈油-助焊剂-光学玻璃清洗剂-贝塔防锈油生产厂家 | 工业插头-工业插头插座【厂家】-温州罗曼电气 | 德州万泰装饰 - 万泰装饰装修设计软装家居馆 | 渗透仪-直剪仪-三轴仪|苏州昱创百科 | 炒货机-炒菜机-炒酱机-炒米机@霍氏机械 | 防水套管|柔性防水套管|伸缩器|伸缩接头|传力接头-河南伟创管道 防水套管_柔性防水套管_刚性防水套管-巩义市润达管道设备制造有限公司 | 环境模拟实验室_液体-气体控温机_气体控温箱_无锡双润冷却科技有限公司 | 螺杆真空泵_耐腐蚀螺杆真空泵_水环真空泵_真空机组_烟台真空泵-烟台斯凯威真空 | 学考网学历中心| 今日热点_实时热点_奇闻异事_趣闻趣事_灵异事件 - 奇闻事件 | 顺辉瓷砖-大国品牌-中国顺辉 | MVR蒸发器厂家-多效蒸发器-工业废水蒸发器厂家-康景辉集团官网 | 网优资讯-为循环资源、大宗商品、工业服务提供资讯与行情分析的数据服务平台 | 厦门网站建设_厦门网站设计_小程序开发_网站制作公司【麦格科技】 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 油液红外光谱仪-油液监测系统-燃油嗅探仪-上海冉超光电科技有限公司 | 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 盐水蒸发器,水洗盐设备,冷凝结晶切片机,转鼓切片机,絮凝剂加药系统-无锡瑞司恩机械有限公司 | 乳化沥青设备_改性沥青设备_沥青加温罐_德州市昊通路桥工程有限公司 | 客服外包专业服务商_客服外包中心_网萌科技 | 过滤器_自清洗过滤器_气体过滤器_苏州华凯过滤技术有限公司 | 杰恒蠕动泵-蠕动泵专业厂家-19年专注蠕动泵| EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 |