-
Not Working
PHP Code:
$mobileno=$_POST['mobileno'];
$var = $mobileno;
substr_replace($var, '+44', 0, 0);
Hi Guys,
Can anyone tell me why the above code doesn't seem to be working, it doesn't seem to be placing +44 at the beginning of $var and instead when the data is added to my database its without the +44.
Any help would be great.
Thanks.
-
I've managed to fix this myself by doing the following:
PHP Code:
$mobile2 = substr_replace($var, '+44', 0, 0);
But how do i go about removing the forth digital in the variable. For example lets say the variable = '+441234567890'
How do i go about removing the forth value (1) from the variable?
Any help would be great.
Thanks
-
This is a quick "stab" at it, but this may work for you:
PHP Code:
$mobileno = $_POST['mobileno'];
$findme = '07';
$pos = strpos($mobileno, $findme);
if($pos === 0)
{
$replace = $substr($mobileno,0,2);
$newMobile=str_replace($replace, "+44",$mobileno);
}
echo $newMobile;
You may want to try making $mobileno = to a number with "07" occurring more than once to make sure that only the first occurrence is replaced.
-
Adwarm,
Just out of curiosity, what kind of project are you working on? Seems cool.
-
yeah that doesn't work if there is more than one occurrence of "07" try this...
PHP Code:
$newMobile = substr_replace($mobileno,"+44",0,2);