我想检查路径是否包含字符串
例如,如果路径包含plugins
,则返回false
,如果路径包含themes
,则返回true
。
D:\wamp\www\wp-content/plugins/someplugin/index.phtml // return false
D:\wamp\www\wp-content/themes/index.php // return true
答案 0 :(得分:1)
我希望这足够了。
<?php
$pos1 = stripos('D:\wamp\www\wp-content/theme/someplugin/index.phtml', 'theme');
if ($pos1 === false) {
echo "Not a theme";
}
else
{
echo "It's a theme !";
}
?>
<强>输出:强>
这是一个主题!
答案 1 :(得分:1)
仅仅因为@Dave Chen问:
So what would wp-plugins or wp-themes trigger?
然后,设置完全匹配:
$themes = "/themes/";
$file01 = "D:\wamp\www\wp-content/themes/index.php";
$file02 = "D:\wamp\www\wp-content/wp-themes/index.php";
$is_theme = stripos($file01, $themes ); // returns true
$is_theme = stripos($file02, $themes ); // returns false