PHP Runtime Issue when Breaking a 10,000 char string into segments
$chapter is a string that stores a chapter of a book with 10,000 - 15,000
characters. I want to break up the string into segments with a minimum of
1000 characters but officially break after the next whitespace, so that I
don't break up a word. The provided code will run successfully about 9
times and then it will run into a run time issue.
"Fatal error: Maximum execution time of 30 seconds exceeded in
D:\htdocs\test.php on line 16"
<?php
$chapter = ("10000 characters")
$len = strlen($chapter);
$i=0;
do{$key="a";
for($k=1000;($key != " ") && ($i <= $len); $k = $k+1) {
$j=$i+$k; echo $j;
$key = substr($chapter,$j,1);
}
$segment = substr ($chapter,$i,$k);
$i=$j;
echo ($segment);
} while($i <= $len);
?>
No comments:
Post a Comment