检查字母/数字的当前URL +文件名

时间:2015-01-28 21:47:50

标签: php

我正在尝试检查域并检查代码的文件名。

这就是我所拥有的:

if($_SERVER['HTTP_HOST']=="http://example.com" && $_SERVER['REQUEST_URI']=='x24'  ) {
    echo "x24 in filename found";
} elseif($_SERVER['HTTP_HOST']=="http://example.com" && $_SERVER['REQUEST_URI']=='b48'  ) {
    echo "b48 in filename found";
} else {
    echo "nothing has been found";
}

因此,如果文件名是http://example.com/directory/abo-ame-ma-x24-file.php,我希望它被检测到,因为文件名中包含 x24 。我想为b48做同样的事情

1 个答案:

答案 0 :(得分:3)

这应该适合你:

(这里我刚用strpos()

if($_SERVER['HTTP_HOST'] == "http://example.com" && strpos($_SERVER['REQUEST_URI'], 'x24') !== false ) {
    echo "x24 in filename found";

} elseif($_SERVER['HTTP_HOST'] == "http://example.com" && strpos($_SERVER['REQUEST_URI'], 'b48') !== false ) {
    echo "b48 in filename found";

} else {
    echo "nothing has been found";
}