Jump to content

I have a PHP script file that I would like to make into a one liner in terminal.

Poet129
Go to solution Solved by mariushm,

You can use the $argv array to read the parameters from command line,  or you can use getopts() to parse the arguments :

 

https://www.php.net/manual/en/reserved.variables.argv.php

https://www.php.net/manual/en/function.getopt.php

 

You can use echo function to output some text on screen. You can use die() to quit.

You can use constants like __DIR__  (the folder the script is located in) or other "magic constants" to make your life easier : https://www.php.net/manual/en/language.constants.predefined.php

There's also other functions like system() , exec() which allow you to launch programs from within the script IF the php is configured to allow it.

 

As for running a script, it's as simple as saying c:/path/to/php/php.exe  script.php argument1 argument2 etc

or ./php script.php argument1 argument2 etc in linux

 

There are some tools that can convert a php script to an executable / binary, but just like python ... it's interpreted code at the end of day, it's not true binary.

 

You can use the $argv array to read the parameters from command line,  or you can use getopts() to parse the arguments :

 

https://www.php.net/manual/en/reserved.variables.argv.php

https://www.php.net/manual/en/function.getopt.php

 

You can use echo function to output some text on screen. You can use die() to quit.

You can use constants like __DIR__  (the folder the script is located in) or other "magic constants" to make your life easier : https://www.php.net/manual/en/language.constants.predefined.php

There's also other functions like system() , exec() which allow you to launch programs from within the script IF the php is configured to allow it.

 

As for running a script, it's as simple as saying c:/path/to/php/php.exe  script.php argument1 argument2 etc

or ./php script.php argument1 argument2 etc in linux

 

There are some tools that can convert a php script to an executable / binary, but just like python ... it's interpreted code at the end of day, it's not true binary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×