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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:57:17+00:00 2026-06-06T14:57:17+00:00

I have php mysql application and i want the phone numbers be saved in

  • 0

I have php mysql application and i want the phone numbers be saved in a specific format. after some googling i reached up to this function:

function RemoveExt($phone) {
    if(substr($phone,0,1) == '+' || substr($phone, 0,2) == 00){
        $phone = preg_replace('/[^\d]/', '', $phone);
        }

    $phone=trim($phone);
    $prefixs=array('0097150','0097156','0097152','0097155', '97150','97156','97155','97152','050','056','055','052','00');

    $replace=array('050','056','052','055','050','056','055','052','050','056','055','052','00');
      $count = count($prefixs); 
for($i = 0; $i < $count; $i++)
    {
        if(strncmp($phone, $prefixs[$i], strlen($prefixs[$i])) == 0){

            $phone = preg_replace('/^'.$prefixs[$i].'/i','',$phone);
             $ext=$replace[$i];
            return array('phone' => $phone, 'ext' => $ext);
        }else{
        return array('phone' => $phone, 'ext' => $ext); 
        } 
    }
}

for example the phone number +971501234567 =>
“+” will be the international code,
“971” will be the country code,
“50” will be the mobile network code and
“1234567” will be the mobile number.

noted that we have more than one mobile code.
The question that I need to save two parts from the number (mobile network code, mobile number)
for example: +971501234567 will be saved as (050) the mobile network code and (1234567) the mobile number.

could anyone help me to achive that?.

  • 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-06T14:57:19+00:00Added an answer on June 6, 2026 at 2:57 pm

    I am going to share the working class :-

        function RemoveExt($phone) {
    
        if(substr($phone,0,1) == '+'){
            $phone = preg_replace('/[^\d]/', '00', $phone);
            }
    
        $prefix=array('0097150','0097156','0097155','0097152','97150','97156','97155','97152','050','056','055','052','00');
    
        $replace=array('050','056','055','052','050','056','055','052','050','056','055','052','00');
          $count =count($prefix);
          $counter=0;
          while( $counter < $count){
                if(strncmp($phone, $prefix[$counter] , strlen($prefix[$counter])) == 0){
    
                    $phone=substr($phone, strlen($prefix[$counter]));
                    $ext=$replace[$counter];
    
                }
                $counter++;
            }
            return array('phone' => $phone, 'ext' => $ext);
    }
    

    Hope help someone.

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

Sidebar

Related Questions

For eg, I have this code for my PHP calendar events application. /**MySQL code
I have a PHP application that I want to switch from MySQL to Cache
We have a PHP/MySQL application and I want to setup a logging mechanism to
I have an existing PHP/MySQL application that I want to convert over to CakePHP.
We have a PHP/MYSQL application that collects user input, including special characters like ø,ü,ñ,
I have a LAMP (Linux/Apache/MySQL/Php) application that I should release soon. Even if I've
I have a small application written in PHP and a mysql database hosted on
I have been working on on an AJAX chat application using php, mysql. It's
I have this piece of php - mysql code: When a user tagged in
I have a PHP MySQL application which has a modular design. There are about

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.