Solved

Converting Phone Number

Posted on 2014-04-14
2
299 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

821 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