任何PHP字符串函数来做这样的事情?

lea*_*ner 0 php php-5.2

$length = strlen($s);

if($length == 10)
{

  $newval = '';
  for($i = 0; $i < 10; $i++)
  {

    $newval .= $s[$i];

    if($i == 2 || $i == 5)  
    {
       $newval .= '-';
    }

  }

}
Run Code Online (Sandbox Code Playgroud)

如果有人知道我会使用什么样的字符串函数,请告诉我.

Jac*_*kin 5

当然,你可以substr用来完成这个:

if(strlen($s) == 10) {
   $s = substr($s, 0, 3) . '-' . substr($s, 3, 3) . '-' . substr($s, 6);
}
Run Code Online (Sandbox Code Playgroud)

键盘示例