Solved

Converting Phone Number

Posted on 2014-04-14
2
300 Views
Last Modified: 2014-04-14
The phone numbers in my DB have this format:
(307)266-3290

I would like to convert them all to this format:
307-266-3290

I think I have to use SELECT CONCAT but not sure how to write the query or optionally just change the output in php.
0
Comment
Question by:seopti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39999175
select concat(concat(substr(PhoneNo,2,3),"-"),substr(PhoneNo,6)) as NewPhoneNo

Replace PhoneNo with the valid field in two places in the above> Of course if you want to change it, it will be an update. I'd run the select first and get that right before updating.
When ready,
Update yourtable
set PhoneNo=concat(concat(substr(PhoneNo,2,3),"-"),substr(PhoneNo,6))

or whatever works in the select
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39999188
Using php:

$number = "(307)266-3290";
$token = array("(", ")");
$replacement = array("", "-");
$number = str_replace($token, $replacement, $number);
echo $number;

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question