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 7753585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:05:26+00:00 2026-06-01T12:05:26+00:00

I have a text file that has item numbers in it (one per line).

  • 0

I have a text file that has item numbers in it (one per line). When an item is scanned by our barcode scanner it gets placed into this text file IF it exists in the order (which is stored in an array…item numbers only, nothing else).

What’s happening is that if I have the two item numbers:

C0DB-9700-W
C0DB-9700-WP

If I scan the item C0DB-9700-W first then I can scan the second item just fine, but if I scan C0DB-9700-WP first, it thinks that I’ve already scanned C0DB-9700-W because that item is a prefix to the item I’ve already scanned.

I know that strpos only checks for the first occurrence. I was using the following code:

if (strpos($file_array, $submitted ) !==FALSE) {

I switched to using:

if (preg_match('/'.$submitted.'/', $file_array)) {

I thought that by using preg_match I could overcome the problem, but apparently not. I just want PHP to check the EXACT string I give it against items in the array (which I’m getting from the file) to see if it has already been scanned or not. This isn’t that hard in my mind but obviously I’m missing something here. How can I coax PHP into looking for the entire string and not giving up when it finds something that will be good enough (or at least what it thinks is good enough)?

Thanks!

  • 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-01T12:05:28+00:00Added an answer on June 1, 2026 at 12:05 pm

    There’s nothing inexact about C0DB-9700-WP containing a match for C0DB-9700-W. What you’re looking for is a regular expression that ensures the string you want is an entire word by itself:

    if (preg_match('/\\b'.$submitted.'\\b/', $file_array)) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have a text file that has pipe (as in the | character)
I currently have a text file that has the following: 1 Commercial & Enterprise
I have a rather large text file that has a bunch of missing newlines,
I have a text file that I want to edit using Java. It has
I have a simple WPF (XAML) file that has some animated shapes and text.
i have a java ee project which has a text file that uses a
I have a text file that contains a long list of entries (one on
I have a text file that has sets of text I need to extract
I have Text file that contains data separated with a comma , . How
I have a text file that contains localized language strings that is currently encoded

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.