Example
Input = 1.1.0.1
Expected output = 1.101
views:
269answers:
5
+7
A:
You could make use substr() and str_replace() fairly easily:
$str = '1.1.0.1';
$pos = strpos($str,'.');
if ($pos !== false) {
$str = substr($str,0,$pos+1) . str_replace('.','',substr($str,$pos+1));
}
echo $str;
zombat
2010-01-30 10:59:51
A:
I though substr_replace()
would work here, but sadly no... Here is a regex approach:
$str = preg_replace('~(\d+\.)(\d+)\.(\d+)\.(\d+)~', '$1$2$3$4', $str);
Alix Axel
2010-01-30 11:07:33
+2
A:
$input="1.1.1.1";
$s = explode(".",$input ) ;
$t=array_slice($s, 1);
print implode(".",array($s[0] , implode("",$t)) );
or
$input="1.1.1.1";
$s = explode(".",$input ,2) ;
$s[1]=str_replace(".","",$s[1]);
print implode(".",array($s[0] ,$s[1] ) );
ghostdog74
2010-01-30 11:11:02
or `array_unshift( $s ) ;`
St.Woland
2010-01-30 11:42:34
A:
$count = 0;
$output = $input;
do {
$output = preg_replace('/^(.+\.)(.+)\./', '$1$2', $output, -1, $count);
} while ($count != 0);
echo $output;
Greg Bacon
2010-01-30 13:10:27