i am trying to build a php script to process data manually to later convert it to a cronjob. this script also get data from mysql and 3rd party soap. when i try to run it from command line i have an error and the script does not run.
我正在尝试构建一个PHP脚本来手动处理数据,以便以后将其转换为cronjob。这个脚本也从mysql和第三方soap获取数据。当我尝试从命令行运行它时,我有一个错误,脚本不运行。
it shows:
表明:
./test.php: line 1: ?php: No such file or directory
Enter a number:
./test.php: line 5: syntax error near unexpected token `('
./test.php: line 5: `$line = trim(fgets(STDIN));'
here's what i have in my script:
这是我脚本中的内容:
echo 'Enter a number:';
$line = trim(fgets(STDIN));
var_dump($line);
i know this script works, what is wrong?
我知道这个剧本有效,有什么不对?
1 个解决方案
#1
18
You get this error because you execute this script like ./script.php
. In order to make sure the PHP script understand and run properly, you have to include this #!/usr/bin/php
at the top of your script.
您收到此错误是因为您执行此脚本,如./script.php。为了确保PHP脚本能够理解并正确运行,您必须在脚本的顶部包含#!/ usr / bin / php。
Example:
例:
#!/usr/bin/php
<?php
echo 'Enter a number:';
$line = trim(fgets(STDIN));
var_dump($line);
if PHP is installed in the /usr/bin folder, if not, you can verify using the locate php
command and then use the right path.
如果PHP安装在/ usr / bin文件夹中,如果没有,则可以使用locate php命令进行验证,然后使用正确的路径。
or the other alternative will be
或者另一种选择
php /path/to/script.php
php /path/to/script.php
#1
18
You get this error because you execute this script like ./script.php
. In order to make sure the PHP script understand and run properly, you have to include this #!/usr/bin/php
at the top of your script.
您收到此错误是因为您执行此脚本,如./script.php。为了确保PHP脚本能够理解并正确运行,您必须在脚本的顶部包含#!/ usr / bin / php。
Example:
例:
#!/usr/bin/php
<?php
echo 'Enter a number:';
$line = trim(fgets(STDIN));
var_dump($line);
if PHP is installed in the /usr/bin folder, if not, you can verify using the locate php
command and then use the right path.
如果PHP安装在/ usr / bin文件夹中,如果没有,则可以使用locate php命令进行验证,然后使用正确的路径。
or the other alternative will be
或者另一种选择
php /path/to/script.php
php /path/to/script.php