Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Converting Phone Number

Posted on 2014-04-14
2
Medium Priority
?
304 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 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