<?php
$str="87455";
$count=strlen($str);
if ($count % 2 == 0)
{
$newcount=$count/2;
$newstr=preg_match_all("/[0-9]{".$newcount."}/", $str, $match);
foreach ($match as $match)
{
$newstr=join("-", $match);
echo $newstr;
}
}
else
{
$newcount=substr($str, 0, intval($count/2));
$newcountc=strlen($newcount);
$nextpart=substr($str, $newcountc, $count);
echo $newcount."-".$nextpart;
}
?>