开发者

How can I add an if statement in a stripos?

开发者 https://www.devze.com 2023-02-27 04:58 出处:网络
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=\') ) { ?>

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')
) {
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号