开发者

parsing error - syntax error, unexpected T_NS_SEPARATOR [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I have this line in PHP:

$bom != b"\xEF\xBB\xBF" 

When I run it, I get the 开发者_C百科error:

Parse error: syntax error, unexpected T_NS_SEPARATOR in
C:\xampp\htdocs\MediaAlbumWeb\Utils\Utils.php on line 218

What is the T_NS_SEPARATOR in php and why is it unexpected?


You likely have an unclosed single or double quote above that line in your code.

What is the b that's outside of the quotes?

If it's a comparison, it could be something like:

if($bom != "b\xEF\xBB\xBF")
{
 //code
}

Simple code to reproduce this error in PHP:

<?php
$arg = "'T';                      //this unclosed double quote is perfectly fine.

$vehicle = ( $arg == 'B' ? 'bus' : 'not a bus');

print $vehicle . "\n";            //error is thrown on this line.  

?>

Run this, it prints an error:

PHP Parse error:  syntax error, unexpected T_NS_SEPARATOR in 
/var/www/sandbox/eric/code/php/run08/a.php on line 6


You do a lot of Python, by any chance? b"string" is not a valid way to write your string in PHP, though it is in Python. If you just want the bytes, then you can write the string out as:

echo "\xEF\xBB\xBF";

That works. If you want to check for inequality:

if( $bom != "\xEF\xBB\xBF" ) {
}

What are you checking for anyway? For a Byte Order Mark? And if so: why, exactly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜