# Php strpos function

**URL:** <https://www.phphelp.com/t/php-strpos-function/33290>\
**Category:** Beginners - Learning PHP\
**Created:** [April 4, 2021, 9:04am UTC](https://www.phphelp.com/t/php-strpos-function/33290 "2021-04-04T09:04:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hunters17](https://www.phphelp.com/letter_avatar_proxy/v4/letter/h/76d3ee/32.png) [@Hunters17](https://www.phphelp.com/u/Hunters17)\
**Post date:** [April 4, 2021, 9:04am UTC](https://www.phphelp.com/t/php-strpos-function/33290/1 "2021-04-04T09:04:54Z")

</div>

Hi there, Im new to this. I have the following code but want to turn it into an ‘if’ statement using strpos function. Currently it excludes the Newsletter page. I would like the straps function to exclude any page that contains the word Newsletter - like NewsletterJan or NewsletterFeb etc etc

Current Code:  
if( $maintenance == ‘disable’ || is\_user\_logged\_in() || $pagenow == ‘wp-login.php’ || is\_admin() || $query-\>query[‘pagename’]== ‘newsletter’) return;

Thanks

Richard

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [April 5, 2021, 1:03am UTC](https://www.phphelp.com/t/php-strpos-function/33290/2 "2021-04-05T01:03:05Z")

</div>

Well, you did not show your strpos code… So, not sure what your heading means compared to the code you showed.

But, this is how you use strpos…

You can find any string inside another with strpos. I am guessing that you want to add this to the $maintenance IF query, you can only do that if there is a string to check if the string exists in. Then, you would use something like if (!strpost($STRINGNAME, “Newsletter”)) then whatever. This will check if the string ($STRINGNAME) does NOT include the the string “Newsletter”, but, of course will not check if the string contains the string “newsletter”. Therefore, you might need to include that option as well.

Now sure it that is what you are requesting, but, hope it helps…

---

<div class="post-metadata">

**Author:** ![whispers](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/858c86/32.png) [@whispers](https://www.phphelp.com/u/whispers)\
**Post date:** [April 5, 2021, 4:01pm UTC](https://www.phphelp.com/t/php-strpos-function/33290/3 "2021-04-05T16:01:44Z")

</div>

Maybe something like this is what you are looking for?

```
$nwsltrCheck = strpos(strtolower ($query->query[‘pagename’]), 'newsletter');  

if( $maintenance == ‘disable’ || is_user_logged_in() || $pagenow == ‘wp-login.php’ || is_admin() || is_numeric($nwsltrCheck)){
    return;
}
```
