I have a variable called $data which contains a giant string (27338 characters).
This string will be the content of a pdf file.
I need to add a footnote at the end of each page of the pdf file.
I’ve calculated 2642 characters per page.
How can I cut $data in chunks of 2642 characters so I can add the footnotes?
I’m trying:
$split = preg_split('/(.{0,2642})\s/',
$data,
0,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$count = count($split);
foreach ($split as $key => $page) {
echo $page; echo "<br><br>";
}
But each $page shows much less than 2642 characters.
Thanks a lot
I never used it with very large amount of data but a way to split strings in elements of equal length is to use the str_split function (see http://php.net/str_split)
usage:
and you will get an array with elements of length 2 (except for the last one)