带有空白的php脚本输出

带有空白的php脚本输出,php,bash,scripting,Php,Bash,Scripting,我正在运行一个脚本,输出首先有一个空格,然后在bash中执行print语句。如何删除这个空格。 请看下面的脚本: !/usr/bin/php <?php $file = '/X/X.txt'; $searchfor = '0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored'; // get the file contents, assuming the file to be readable (and exist) $contents

我正在运行一个脚本,输出首先有一个空格,然后在bash中执行print语句。如何删除这个空格。 请看下面的脚本:

!/usr/bin/php
<?php
$file = '/X/X.txt';
$searchfor = '0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored';
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
    print("OK: No Input Errors Found");
    exit(0);
}
else{
   print ("Warning");
    exit(1);
}
?>
/usr/bin/php
输出将如下所示,并留有空白:

/剧本
警告#bash

尝试在字符串周围添加trim(),这将删除字符串开头和结尾的空格

我已经找到了答案,我不得不删除下面的空白:

!/usr/bin/php 空位 下面的内容对我很有用,谢谢大家。
!/usr/bin/php只是一个注释,文件的开头必须是这样的:
#/usr/bin/php
很抱歉,我犯了一个打字错误。我添加了trim(),空白仍然存在。您运行的是什么操作系统?在我的debian系统上没有多余的空格。