How can I add an if statement in a stripos?
how can I keep the p= and add an OR /20 on it ? I mean I want to check both strings.
<?php if ( 开发者_JAVA技巧false==stripos(get_permalink($post->ID), 'p=') ) { ?>
You cannot test for two portions of strings with a single stripos()
call : you have to call stripos()
twice.
Depending on what you exactly want to achieve (not sure I really undertand the question), you'll combine those two with &&
or ||
:
$link = get_permalink($post->ID);
if (stripos($link, 'p=')!==false && stripos($link, '/20')!==false) {
// the link contains both p= AND /20
}
or :
$link = get_permalink($post->ID);
if (stripos($link, 'p=')!==false || stripos($link, '/20')!==false) {
// the link contains p= OR (inclusive) /20
}
As a sidenote : you should use ===
or !==
, as stripos()
can return 0
or false
-- and those don't have the same meaning.
You have to call it twice:
if( false===stripos(get_permalink($post->ID), 'p=') ||
false===stripos(get_permalink($post->ID), '/20')
) {
精彩评论