我以为我了解PHP的strcmp()
函数,直到我编写了在为'1'
拍摄时生成'0'
的代码。
我正在测试的代码使用$CSVStandard
将.gz文件第一行中的字符串与字符串变量strcmp()
进行比较。
$gzstr = 'user_2020-06-24_000test.csv.gz';
$openFile = gzopen($gzstr,"r");
$gzgetsBuffer = gzgets($openFile);
gzclose($openFile);
$CSVStandard ='"user_id","create_time","last_process_day","expiry_time","billing_zip","shipping_zip","domain","os_type","delivery_date","fwd_enabled_date"';
$c=(strcmp($CSVStandard,$gzgetsBuffer));
echo "gzgetsBuffer:"."<br>".$gzgetsBuffer."<br>";
echo "CSVStandard:"."<br>".$CSVStandard."<br>";
echo "Output of strcmp(): ".$c."<br>";
echo "Reverse parameters in strcmp(): ".(strcmp($gzgetsBuffer,$CSVStandard));
我也颠倒了参数,得到了-1
。有没有隐藏的东西或gzgets()
使用的指针,我看不到?
以下是输出:
Output gzgets:
"user_id","create_time","last_process_day","expiry_time","billing_zip","shipping_zip","domain","os_type","delivery_date","fwd_enabled_date"
CSVStandard:
"user_id","create_time","last_process_day","expiry_time","billing_zip","shipping_zip","domain","os_type","delivery_date","fwd_enabled_date"
Output of strcmp(): -1
Reverse parameters in strcmp(): 1
答案 0 :(得分:-1)
我认为您的代码是正确的。但是user_2020-06-24_000test.csv
文件具有一些隐藏的内容,例如换行'\ n'。