-2

我想检查路径是否包含字符串,

比如,如果路径包含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
4

2 回答 2

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
于 2013-09-08T07:08:27.717 回答
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 !";
}
?>

输出:

这是一个主题!

于 2013-08-16T05:30:26.630 回答