[eluser]Rurik[/eluser]
Ok, so this is not strictly related to code igniter, but php forumns are usually rather unhelpful.
I have a phone number, lets say 0401 000 000.
I need to remove the spaces from these and put the number back together (its a string and i convert to int later).
I have tried using explode, and I have tried using substr but whenever I put it back together, it becomes 401000, losing the leading 0 and the second lot of trailing 0's.
For example, I am currently using the following code:
Code:
$string = "1";
$num1 = substr($d['contactno'], 0, strpos($d['contactno'], " ", 0));
$num2 = substr($d['contactno'], strpos($d['contactno'], " ", 0)+1,strrpos($d['contactno'], " ")-strpos($d['contactno'], " ", 0));
$num3 = substr($d['contactno'], strrpos($d['contactno'], " ")+1);
if($num1 != $num3)
{
$string = $string.$num1.$num2.$num3;
}
echo $d['contactno']."</br>";
echo $num1."</br>";
echo $num2."</br>";
echo $num3."</br>";
$string = substr($string, 1);
$d['contactno'] = (int)$string;
echo $d['contactno']."</br>";
and the results are as follows:
0401 000 100
0401
000
100
401000
Any ideas for how I could go about this? Its really starting to frustrate me.
Regards,
Rurik