duanbo2048 2012-09-18 17:48
浏览 168
已采纳

从命令行调用PHP脚本中的函数

I have a script that has a bunch of different parameterized functions. Is it possible to call any of these functions from the command line and pass in the arguments instead of me having to hard code the function calls in the script?

F.Y.I: I do know how to execute a simple PHP script from the command line

doesn't quite call the function, remember script.php has around 5 different functions and I am looking to call only 1, is that possible

  • 写回答

6条回答 默认 最新

  • douke1942 2012-09-18 17:51
    关注

    No, you cannot do that directly. You have a few options:

    • Put every function in a separate php file and call the php file
    • use the first argument passed to the php file as the function name, and write a few lines of code to select the correct function.

    Update:

    Here is a example of using the first passed parameter as a function call:

    if(function_exists( $argv[1] ))
      call_user_func_array($argv[1], $argv);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。