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?
精彩评论