语法错误附近意外的标记`<'

我已经在并行plesk 10.4.4服务器上的cron作业中设置php文件。在通知电子邮件中显示错误。

syntax error near unexpected token `<' syntax error near unexpected token `newline' /newsletter_auto.php: line 2: `<html>' 

newsletter_auto.php文件的代码如下

  <title>Market Trend Newsletter</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ var abc=encodeURIComponent($("#newsletter").html()); $.ajax({ type:'POST', url:'newsletter_automation.php?abc='+abc, success:function(data){ } }); }); </script> </head> <body> <?php function checkForNULLString($str) { if($str == "" || $str == " " || $str == " " || $str == " " || $str == " " || $str == " " || $str == " " || $str == null) { return false; } else { return true; } } function cleanForDatabase($str) { $str = preg_replace('/[^a-zA-Z0-9\s-_#@.,]/', '', $str); $str = mysql_real_escape_string($str); return $str; } function runSQLQuery($query,$mysqlConnect) { $result = mysql_query($query,$mysqlConnect); if(mysql_errno($mysqlConnect) != 0){ echo "\n !<u>!ERROR:</u>mysqlConnect:".$mysqlConnect." <br/>query:".$query."<br/> Query.result:" . mysql_errno($mysqlConnect) . ": " . mysql_error($mysqlConnect) . "\n"; //Log the Query Error $result = mysql_query($query,$mysqlConnect); exit(); } return($result); } function insertIconAdminLink($link,$name,$type,$text=NULL,$target="_self") { //print"<a href=\"".$link."\" onmouseout=\"Javascript:roll_over_switch('".$name."',false);\" onmouseover=\"Javascript:roll_over_switch('".$name."',true);\"><img name=\"".$name."\" id=\"".$name."\" border=\"0\" src=\"/images/".$type.".gif\" />".$text."</a>"; print" <a class=\"iconLinkText\" href=\"".$link."\" target=\"".$target."\"><img name=\"".$name."\" id=\"".$name."\" border=\"0\" src=\"/images/".$type.".gif\" width=\"24\" height=\"24\" />".$text."</a> "; } <div id="newsletter"> <p>Stocks traded <?php echo $stock_direction; ?> today with the <?php echo $stock_index; ?> closing at <?php echo $stock_index_close; ?>, <?php echo $stock_direction; ?> <?php echo $stock_index_difference; ?> or <?php echo $stock_index_percentage_difference; ?> from the previous close. The number of NYSE advances were <?php echo $nyse_advances; ?>, the number of decliners was </div> </body> </html> 

请让我知道如何解决这个问题?

如果你在bash脚本解释器下执行一个php模板文件,例如test.php,那么这就是你所期望的错误,例如,如果你创build一个基本的php脚本文件;

 $ echo -e "<html>\n</body><?php echo 'test'?></body></html>" > ~/test.php $ cat test.php <html> </body><?php echo 'test'?></body></html> 

并使其可执行,然后尝试直接执行它…

 $ chmod +x test.php $ ./test.php ./test.php: line 1: syntax error near unexpected token `newline' ./test.php: line 1: `<html>' 

这是因为shell正试图在默认脚本解释器下运行脚本,即bash,它相当于这个;

 $ bash test.php test.php: line 1: syntax error near unexpected token `newline' test.php: line 1: `<html>' 

至less,像这样的东西至less可以在php下运行php脚本;

 $ /usr/bin/php test.php <html> </body>test</body></html>