Hi,
ok, basically i have a number in the format
07736 284 827
and i want to turn it into
+447736284827
any ideas how? i'm stuck on removing the 0 if there is one as sometimes the number will be entered as 7736... etc
Alex
| SitePoint Sponsor |



Hi,
ok, basically i have a number in the format
07736 284 827
and i want to turn it into
+447736284827
any ideas how? i'm stuck on removing the 0 if there is one as sometimes the number will be entered as 7736... etc
Alex
Nearly 7 years old!
I'm a bit confused..
00 to 44? What for?![]()
What exactly are you trying to do? Get rid of zero's? Zero's and spaces? Zero's at the begining and spaces?
Regards,
Someonewhois
P.S. Long time no see.![]()
- Nathan



ok, i guess i didn't explain properly
in the UK, the format of a mobile (cell) number is usually used/wrote as
07747 372 482 for example
a 0, always followed by 4 digits (network code) and then 6 digits (number)
i want to convert this to a international format number, i.e
+447747372482
exaxtly the same, but no preceding 0 and a +44 on the end
the problem is removing the 0 only if it is there
i.e
<?php
if (0 is there) {
remove 0
}
$mnumber = "+44" . $mnumber;
?>
if that makes sense
Nearly 7 years old!
Hmmmm, my regex isn't that good, but this should do it:
Will that work?PHP Code:$txt = "07747 372 482"; // I use quotes on numbers as if it's a string, not an int most of the time..
$txt = ereg_replcae("^0", "", $txt);
$txt = "+44".$txt;
"^0" meaning if the 0 is at the begining?
Regards,
Someonewhois
P.S. What did you have that didn't work?
[Edit: Oh, I added 1 "4" instead of 2 accidentally]
[Edit2: Argh, I want ereg_replcae, not preg_replace..]
- Nathan



You could do this:
PHP Code:<?php
$txt = str_replace(" ", "", $txt);
if(substr($txt, 0, 1) == "0"){
$txt = substr($txt, 1);
}
$txt = "+44" . $txt;
?>



Looks like someonewhois beat me to it.You forgot to remove the spaces in the $txt variable though.
![]()
Yeah, and if you REALLY want that if() to check if it has it or not:
BTW, that won't give spaces nowPHP Code:$txt = "07747 372 482";
if (ereg("^0", $txt))
{
$txt = ereg_replcae("^0", "", $txt);
}
$txt = str_replace(" ", "", $txt);
$txt = "+44".$txt;
![]()
![]()
- Nathan
I just had to help himOriginally posted by Coomer
Looks like someonewhois beat me to it.![]()
AlexC was the one who got me started both at PHP, and when I was getting so many errors, he's the one who sent me to SPF, and I'm glad he did!![]()
- Nathan



hehe... been a while since i've done much coding (and needed help..) - ok, someonewhois - your solution produces this error:
Any ideas? - i'm going to try coomers idea nowCode:07732495603 Warning: No ending delimiter '^' found in /home/teravox/public_html/fonewow/channels/mobileprocess.php on line 44 +44
Thanks :-D
Nearly 7 years old!



coomer, you are a genius - with a little work from both of your solutions i got the script working, the number outputs perfectly now
Thankyou both of you! :-D
Nearly 7 years old!
I don't use regex much
PHP Manual:
ereg ("^abc", $string);
/* Returns true if "abc";
is found at the beginning of $string. */
Beats me
Glad you figured it out![]()
- Nathan
Bookmarks