How to pass parameters from bash to php script?

前端 未结 3 1783
失恋的感觉
失恋的感觉 2020-12-03 20:48

I have done a a bash script which run php script. It works fine without parameters but when I add parameters (id and url), there are some errors:

PHP Deprec         


        
3条回答
  •  萌比男神i
    2020-12-03 21:27

    Call it as:

    php /path/to/script/script.php -- 'id=19&url=http://bkjbezjnkelnkz.com'
    

    Also, modify your PHP script to use parse_str():

    parse_str($argv[1]);
    

    If the index $_SERVER['REMOTE_ADDR'] isn't set.


    More advanced handling may need getopt(), but parse_str() is a quick'n'dirty way to get it working.

提交回复
热议问题