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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:33:44+00:00 2026-05-28T01:33:44+00:00

I am storing sms received from twilio in a database so I can use

  • 0

I am storing sms received from twilio in a database so I can use them later. When I did this in the sandbox it worked. However when I upgraded to a regular phone number the number received is the same as was sent to, but +1 (or for xxxxxxxxxx where the x’s are the original number, it looks more like 1xxxxxxxxxx+)

I therefore changed the mysql_query to the following: but it is still not working. What can be done to recognize that this is the original phone number?

<?php
    $starttime = time(); 
    $number = $_POST['number'];

    $number1 = "1" . $number;
    $number2 = $number . "1";
    $number3 = "+1" . $number;
    $number4 = $number . "+1";
    $number5 = "+" . $number . "1";
    $number6 = "1" . $number . "+";
    $number7 = $number."1+";

    $received = mysql_query("SELECT * FROM sms_received 
                WHERE (responder='$number' OR responder='$number1' 
                     OR responder='$number2' OR responder='$number3' 
                     OR responder='$number4' OR responder='$number5'
                     OR responder='$number6' OR responder='$number6')
                AND (body='y' OR body='yes' OR body='Y' OR body='Yes' OR 'yea' OR 'Yea')
                AND timestamp BETWEEN ".date('Y-m-d H:i:s', strtotime($starttime))." AND NOW()"); 
?>

But still, nothing is being received. Any ideas how else I can check whether an sms has been received from the user? I can see in the database that it’s there… but the mysql isn’t finding it. It worked before, when the number sent was identical to the number received from, but with the added +1 it screws it up. (the code before just had WHERE responder = '$number' and it worked, but the additional variables didn’t help it).
Does this code have too many OR’s? Is that even a problem?

UPDATE:

Thanks, here is the function I’m using to strip the number down to xxxxxxxxxx format, before saving it to the database:

function checkPhone($responder){
    $items = Array('/\ /', '/\+/', '/\-/', '/\./', '/\,/', '/\(/', '/\)/', '/[a-zA-Z]/');
    $clean = preg_replace($items, '', $responder);

    if (substr($clean, 0, 1) == "1") {
        return substr($clean, 1, 10); 
    }
    else {
        return substr($clean, 0, 10);   
    }
}

$number = checkPhone($responder);
  • 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-28T01:33:45+00:00Added an answer on May 28, 2026 at 1:33 am

    Twilio returns numbers in a format called E.164, which is an internationally recognized standard for phone number formatting.

    In general, it’s best practice to standardize the number to E164 BEFORE you store it in the database. That way you don’t have to worry about storing different data with two different copies of the same number – eg 925-555-1234 and (925) 5551234.

    Google has a libphonenumber library that will convert numbers for you. It works with Javascript, C++, Java, and Python.

    If you are using PHP, and only using US/Canadian numbers, you can write a function to normalize phone numbers, that does something like the following:

    - Strip out all non number characters from the phone number 
      (parentheses, dashes, spaces) - you can use a function like preg_replace
    - if the phone number begins with a +1, do nothing
    - if the phone number begins with a 1, add a +
    - else, add a +1 to the beginning of the number.
    - finally, store it in the database.
    

    I hope that helps – please let me know if you have more questions.

    Kevin

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

Sidebar

Related Questions

I have a BroadcastReceiver that when a SMS is received it queries database and
Is storing secret keys (internal use passwords and such) on iPhone source code and
Im storing columns in database with users able to add and remove columns, with
I am storing a PNG as an embedded resource in an assembly. From within
I'm storing a Word document in a SQL Server 2005 database in a varbinary(max)
We're storing some Guid's in a MS SQL database. There's some legacy code that
I am working on a android application which read the sms from content provider.
I have an application which requires data to be fetched from a received message
When I query the content://sms/ content provider and pull information from the address column;
I would like to delete an SMS from the inbox once it is read

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.