

Different format number depending on mobile phone or business
source link: https://www.codesd.com/item/different-format-number-depending-on-mobile-phone-or-business.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Different format number depending on mobile phone or business
Currently in my php application I have the following code that formats the unformatted 10 digit australian phone number to XX XXXX XXXX
. What I would like to do is if the phone number in the database starts with 04
then it will format it as 4,3,3 like XXXX XXX XXX
otherwise will maintain the 2,4,4 formatting. All phone numbers are stored in the database as XXXXXXXXXX
.
Here is my code so hopefully someone can shed some light. I know there needs to be an if statement, but unsure how to check the first 2 digits of the number for the 04
.
<?php
$num = $record['busphone'];
$phoneformated = substr($num,0,2)." ".substr($num,4,4)." ".substr($num,6);
echo "Ph: " . $phoneformated;
?>
Compare the substring in an if
statement:
if (substr($num, 0, 2) == '04') {
$phoneformatted = substr($num, 0, 4) . " " . substr($num, 4, 3) . " " . substr($num, 7);
} else {
$phoneformatted = substr($num, 0, 2) . " " . substr($num, 2, 4) . " " . substr($num, 6);
}
Notice that you had a typo in formatting the residential numbers, substr($num, 4, 4)
should be substr($num, 2, 4)
.
Recommend
-
38
Raymond November 6th, 2019 Here’s something crazy: You have a function that has two different callers. One of...
-
9
Blank Zero Values in .NET Number Format Strings ...
-
9
The process to format a number as currency can be a tedious task. It feels like a small task, but the number of lines and the edge cases can keep on increasing when considering factors such as internationalization and different formattin...
-
22
Home » How To Guides » JavaScript » How to Format Date with Ordinal Numb...
-
8
Showing different titles depending if the tab is active or not Thursday, February 10th, 2022 at 7:49 pm I just encountered a sneaky thing I had not seen, although it probabl...
-
11
How do I fix my php number_format error? advertisements I am getting the error below with my array code. How ca...
-
8
Ask HN: How can scam callers fake a mobile phone number? Ask HN: How can scam callers fake a mobile phone number? 99 points by
-
1
The Q notation is a way to specify the parameters of a binary fixed point number format. A number of
-
8
How to Format a Number as Currency in JavaScript This article will...
-
9
React Native International Phone Number Input
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK