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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:19:20+00:00 2026-05-11T18:19:20+00:00

I am wondering what other approaches you would take to do some simple string

  • 0

I am wondering what other approaches you would take to do some simple string splitting in PHP. I am receiving a response from a SMS gateway where two of the interesting values are the code used and the users text message.

The code could be something like: Freetrip (lowercase, uppercase, mixed case)

The user message should in the best case scenario be e.g. like: Freetrip 12345 ($code “space” XXXXX).

Each X should be a digit between 1 and 5. Any other value/character should return an error. So the regex would be simplified as: chars=5 where each digit >=1 and <=5.

What I need to store at the end would be each of the 5 digits values.

My simplest approach would be to lowercase the entire message string and subtract the also lowercased code (plus the space) from the message string. That would leave me with the 5 digits which I would then split into 5 unique variables to store in the DB.

Now the tricky part is that the best case scenario described above may be hard to achieve. Typing a SMS is fiddly and typing errors occur easily. Some errors that may occur are the following:

  • Too few or many digits.
  • Non-digits characters.
  • More characters after the XXXXX combination.
  • Probably some other cases.

Any of those should return an individual error message which I can return to the sender.

  • 1 1 Answer
  • 1 View
  • 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-11T18:19:20+00:00Added an answer on May 11, 2026 at 6:19 pm
    if (!preg_match('/^freetrip\s+([1-5]{5})$/i', $sms, $matches)) exit("error");
    print_r($matches);
    

    I had some experience with SMS-platforms and AFAIK one error is enough. We tried to detect similar characters like small L and big I etc, or zero and O-letter. For example in your case you could write something like this:

    preg_match('/^freetr[il1|]p\s+([1-5]{5})$/i', $sms, $matches);
    

    the same you can do in any place of message pattern (if you want).

    I did something like this (not sure – it was 5 years ago):

    if (!preg_match('/^(\w+)\s+(.*)/i', $sms, $matches)) exit('bad message format');
    $value = $matches[2];
    
    // some letters look like digits
    $value = str_replace(array('o', 'O'), 0);
    $value = str_replace(array('i', 'I', 'l'), 1);
    if (!preg_match('/^[12345]{5}/')) exit("invalid code");
    // do something here... message is OK.
    

    Sure in this case you can check “freetrip” or not, value is [1-5]{5} or not etc, and response your error as much as allows your imagination :). Good luck.

    EDIT: The last one is updated and should fit your case. It’s better, because it will be very simple to create another service on it’s example if you’ll need it.

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

Sidebar

Related Questions

No related questions found

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.