我遇到了一个类似的问题,当我从 mysql 中提取一个值时,当我将它与文件名进行比较时,它总是返回 -6。仅当我从 mysql 提取信息时才会发生这种情况
path rp_suzrl250.jpg strFile rp_suzrl250.jpg
strcmp value -6
path 2009_Evo.jpg strFile 2009_Evo.jpg
strcmp value -6
path DSCF6495.JPG strFile DSCF6495.JPG
strcmp value -6
$strFile = $dbrow[bikepicture];
if($dh = opendir($file)){
while(($path = readdir($dh)) !== false){
$path = (string)$path;
$strFile = (string)$strFile;
echo "filename: " . $path . " " . strcmp($path, $strFile) . "<br>";
if ($path === $strFile){
echo $path . " got here " . "<br />";
}
}
}
if (strtoupper($path) === strtoupper($strFile)){ }
转换为字符串失败并且转到上层失败。它返回-6。
最佳答案
我的“答案”仅包含问题,但它们可能会引导您找到解决方案。
你的 $strFile 是字符串吗?使用 var_dump($strFile) 你会得到什么? 我假设您的代码片段位于此类循环内:
$results = $cnn->query($query);
while ($dbrow = $results->fetch_array(MYSQLI_ASSOC)) {
...
}
如果这是正确的,您应该使用 $strFile = $dbrow['bikepicture'],因为否则 bikepicture 会被解释为常量。顺便问一下,您没有收到警告/错误吗?
关于php - 当从 mysql 在 php 中执行 strcmp 时,它返回 -6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19104463/