Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:34:23+00:00 2026-05-31T13:34:23+00:00

I am trying to use strpos to find out if a string exists and

  • 0

I am trying to use strpos to find out if a string exists and then use substr_replace to delete that string. My code is below:

  $title=$item->get_title();
        $stringToFind='Help needed identifying this person in ';
        if(strpos($title,$stringToFind)){
            $title=substr_replace($title,'',0,strlen($stringToFind));
        }

However, when I do an echo on the strpos it always returns false when it should be true. So I’m wondering if strpos doesn’t do whitespace or something? IN which case can someone recommend something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:34:24+00:00Added an answer on May 31, 2026 at 1:34 pm

    Why don’t you give this a shot :

    $searchStr = 'Help needed identifying this person in ';
    $title = str_replace($searchStr,'',$title);
    

    The PHP documentation refers to the str_replace function as

    Replace all occurrences of the search string with the replacement string.

    If the $searchStr does not appear in the $title variable then the string will be left alone.
    However, if it exists – it will be removed. You don’t need to test if it exists at all. If you need to test whether a change has been made or not you could compare the length of the two strings using strlen or mb_strlen depending on your encoding.

    Example input/outputs :

    CONSTANT – $searchStr = 'Help needed identifying this person in ';

    // A match is found - string is changed
    IN -> Help needed identifying this person in Timbuktu
    OUT -> Timbuktu
    
    IN -> Help needed identifying this person in Zimbabwe
    OUT -> Zimbabwe
    
    IN -> Help needed identifying this person in Netanya
    OUT -> Netanya
    
    // A match is not found - string remains the same
    IN -> Stack Overflow is a programming Q & A site that’s free.
    OUT -> Stack Overflow is a programming Q & A site that’s free.
    
    IN -> We don’t run Stack Overflow. You do.
    OUT -> We don’t run Stack Overflow. You do.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello people :) I'm trying to use strpos() to find whole words in a
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying use the Str[fixnum] to return a specific portion of a string. #
I'm trying to use curl to detect whether a piece of text exists in
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
When I run the decorate_keyword() function below, I'm getting two errors that I'm trying
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a
I'm trying use preg_match in an IF statement and return false if a string
I am trying use the jQuery table sorter plugin for a table that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.