使用PHP检查URL中的某些单词

a.m*_*a.m 1 php

我正在尝试编写一个PHP代码,检查网址中是否有某个单词,如果有的话 - 显示一些内容.

我正在使用这个:

$url = parse_url($_SERVER['REQUEST_URI']);

if($url['path'] == '/main-category/') {
echo........
Run Code Online (Sandbox Code Playgroud)

例如,我正在寻找"主要类别".对于http://www.site.com/main-category/,代码正在运行,但如果网址包含子类别http://www.site.com/main-category/sub-category/,则不是.

我怎样才能找到/主要类别/无论是否有什么东西?

我在这里阅读了一些主题,但没有弄清楚.

Joh*_*nde 7

使用strpos().手册中的示例:

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?>
Run Code Online (Sandbox Code Playgroud)