parsing error - syntax error, unexpected T_NS_SEPA

2019-01-28 08:26发布

I have this line in PHP:

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

When I run it, I get the 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?

2条回答
孤傲高冷的网名
2楼-- · 2019-01-28 09:01

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?

查看更多
够拽才男人
3楼-- · 2019-01-28 09:03

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
查看更多
登录 后发表回答