How to execute PHP code from the command line?

前端 未结 5 940
逝去的感伤
逝去的感伤 2020-12-04 06:41

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

5条回答
  •  一整个雨季
    2020-12-04 07:17

    Using PHP from the command line

    use " instead of ' on windows when using the cli version with -r

    php -r "echo 1"
    

    -- correct

    php -r 'echo 1'
    

    -- incorrect

      PHP Parse error:  syntax error, unexpected ''echo' (T_ENCAPSED_AND_WHITESPACE), expecting end of file in Command line code on line 1
    

提交回复
热议问题