【发布时间】:2019-01-16 14:16:03
【问题描述】:
我有一个文件夹结构,两个文件夹被命名为 ComputerScience 和 Science
问题是当我需要同时匹配变量时,我的代码总是检测到变量包含科学。
我正在使用
if (strpos($dir, "ComputerScience") !== FALSE) {
$my_full_path= $dir;
$sql = "UPDATE documents
SET subject = 'ComputerScience'
WHERE documentname='".$dir."'";
mysqli_query($link,$sql);
}
和
if (strpos($dir, "Science") !== FALSE) {
$my_full_path= $dir;
$sql = "UPDATE documents
SET subject = 'Science'
WHERE documentname='".$dir."'";
mysqli_query($link,$sql);
}
我猜第二个代码块正在覆盖第一个被匹配的代码块,如果 $dir 变量包含它,我如何对字符串进行精确匹配?
谢谢
【问题讨论】:
-
您能否将 $dir 变量的值附加到问题中?