Jump to content

Recommended Posts

I am trying to convert a variable that contains a telephone number in  this format: (800) 555-1212 to this format:8005551212.

 

 

The variable that contains the number is the initial $to:

 

function transfer($from,$to){
                $this->log->debug("in function transfer($from, $to)");
                if(empty($from) || empty($to)) {
                        echo "Not sufficient parameters to create the call";
                        $this->log->debug("Not sufficient parameters to create the call");
                        return false;
                }
	  $to = "sip:$to";
               	

 

 

So for right now, $to ens up being "sip:(800)555-1212" I want it that it ends up being "sip:8005551212".

 

 

Thanks

To clarify these items.  ignace's code will trim out all "(" ")" and "-" of the number.  My function will ONLY return numbers.  SO if someone had "(800)@5#5!5$ - 12-12" for the phone number field ignace code would return "800@5#5!5$  1212" and mine would return "8005551212"

To clarify these items.  ignace's code will trim out all "(" ")" and "-" of the number.  My function will ONLY return numbers.  SO if someone had "(800)@5#5!5$ - 12-12" for the phone number field ignace code would return "800@5#5!5$  1212" and mine would return "8005551212"

 

REGEX is IMO to much overhead for something this simple

REGEX is IMO to much overhead for something this simple

 

Well, that assumes this IS simple. True, if ALL the values are exactly in the same format, str_replace() would be faster. But, we are talking about hundredths if not thousandts of seconds. Nothing that would affect overall performance in the least. Plus, a regex expression will have more flexibility as you can create a single regex expression that could process many different types of formats - or the formats chould change and the regex would continue to work. With a str_replace() you would need to have specific logic to handle multiple formants and you would need to change it if the inputs were to ever change.

 

Again, as long as the format will ALWAYS be the same, str_replace() will suffice. But, only if that is the case.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.