What PHP functions can be used to divide a long text into smaller sections for display on separate pages?
To divide a long text into smaller sections for display on separate pages, you can use the `substr()` function in PHP to extract a portion of the text based on a specified start and length. You can also use the `strlen()` function to determine the length of the text and then divide it into chunks for display on different pages.
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
$chunkSize = 100;
$totalChunks = ceil(strlen($text) / $chunkSize);
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $chunkSize;
$chunk = substr($text, $start, $chunkSize);
echo $chunk;
echo "<br><br>";
for ($i = 1; $i <= $totalChunks; $i++) {
echo "<a href='?page=$i'>$i</a> ";
}
Related questions
-
PHP counter script statistics
-
IP address security concerns PHP scripts
-
PHP input validation sanitization