如何检查字符串$ _GET [“s”]中是否包含++++?

时间:2010-12-11 22:35:54

标签: php wordpress

我也可以用get_search_query()调用$ _GET [“s”],它输出一个字符串。

我尝试了许多应该有效的代码,但没有。无论我做什么,大多数都是真的有没有一个简单的方法来做到这一点?感谢

3 个答案:

答案 0 :(得分:1)

假设你的意思是文字字符串“++++”......

if (strpos($_GET['s'], '++++') !== false) {
    // there, do something
} else {
    // not there, do something else
}

参考:http://php.net/strpos

答案 1 :(得分:1)

if( strpos( $_GET['s'], '++++' ) !== false ) {
    // has
} else {
    // doesn't have
}

答案 2 :(得分:1)

我不确定你有什么困扰,或者我是否误解了这个问题,但肯定strpos就是你所需要的:

if (strpos($_GET["s"],'++++') !=== false) {
   // the string '++++' was found
}

<小时/> 已编辑以修复'strpos'(即'strpoa')错误...哎呀!感谢@Jonah Bron =)