21,887
社区成员
发帖
与我相关
我的任务
分享
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
$str = "fjldsajfljasdljfljsdalfjlsadjfjsfjsdlafjl;asjdfljsw";
$str2 = '';
for ($i = 0; $i < 100000; $i++) {
$str2 .= $str;
}
//方法二
$len = ceil(strlen($str2) / 10);
for ($i = 0; $i < $len; $i++) {
echo substr($str2, $i*10, 10);
echo "<br/>";
}
//方法一
//for ($i = 0; $i < strlen($str2); $i ++) {
// echo ($i != 0 && $i % 10 == 0) ? "<br/>" : '';
// echo $str2[$i];
//}
//
////方法三
//echo wordwrap($str2, 10, "<br/>", true);
//echo "<br/>";
$time_end = microtime_float();
$time = $time_end - $time_start;
echo strlen($str2) . "<br/>";
echo " in $time seconds\n";
?>
$str = "165168161531321321afdsfdsgtrg34577876mjgmhgndsvcds23432";
for ($i = 0; $i < strlen($str); $i ++) {
echo $str[$i];
echo $i % 10 == 0 ? "<br/>" : '';
}