$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)
如果有人知道我会使用什么样的字符串函数,请告诉我.
当然,你可以substr用来完成这个:
if(strlen($s) == 10) {
$s = substr($s, 0, 3) . '-' . substr($s, 3, 3) . '-' . substr($s, 6);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |