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

  • Home
  • SEARCH
  • 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 7904909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:16:31+00:00 2026-06-03T10:16:31+00:00

How do I find exact 2, in a string using strpos? Is it possible

  • 0

How do I find exact 2, in a string using strpos? Is it possible using strpos? The example below returns “Found” even though the match is NOT exact to what I need. I understand 2, is matching with 22,. It should return “Not Found”. I am matching ID’s in this example.

$string = "21,22,23,26,";
$find = "2,";

$pos = strpos($string, $find);
if ($pos !== false) {
   echo "Found";
} else {
   echo "Not Found";
}
  • 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-06-03T10:16:32+00:00Added an answer on June 3, 2026 at 10:16 am

    Unless the string is enormous, make an array and search it:

    $string = "21,22,23,26,";
    $arr = explode(",", $string);
    
    // array_search() returns its position in the array
    echo array_search("2", $arr);
    // null output, 2 wasn't found
    

    Actually, in_array() is probably faster:

    // in_array() returns a boolean indicating whether it is found or not
    var_dump(in_array("2", $arr));
    // bool(false), 2 wasn't found 
    var_dump(in_array("22", $arr));
    // bool(true), 22 was found
    

    This will work as long as your string is a comma-delimited list of values. If the string is really long, making an array may be wasteful of memory. Use a string manipulation solution instead.

    Addendum

    You didn’t specify, but if by some chance these strings came from a database table, I would just add that the appropriate course of action would be to properly normalize it into another table with one row per id rather than store them as a delimited string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the Sql Server 2008 how can you actually find an exact string match
Got a list saved by using .data(). How is it possible to find exact
similar questions have been asked before but I cant find an exact match to
I'm using regular expressions to find some values in a string, however, what I'm
I'm not entirely sure if this is possible and tried searching but couldn't find
How do i find out if a string is containing the exact word i
I am using jQuery.autocomplete(1.02) on my search box and I want exact string and
Note: I was unable to find this exact question in a search. I found
In my application,I want to find the exact coordinates of the objects detected in
I've already looked around but couldn't find the exact solution/problem I'm having right now.

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.