Call a PHP function from the command line
By using the -r
parameter you can run a script in-line.
php -r "require 'address.php'; exportAddress(12345);"
There are no other options. A function in PHP can only be called by a PHP script.
Add this to the top of the file "/var/www/test/address.php"...
foreach ($argv as $i=>$arg )
{
if ( $arg == "exportAddress" )
{
exportAddress($argv[$i+1]);
}
}
Then from the command line, execute:
php /var/www/test/address.php exportAddress 12345
Use
php -r 'include "/var/www/test/address.php";exportAddress(1);'
where "/var/www/test/arr.php"
is the file name, including path, and exportAddress()
is a function inside that file.