Jump to content

Break text into chunks


jaxdevil

Recommended Posts

I found a code to do what I need but I do not know how to call each split chunk. What I need to do is split each chunk into 500 character segments and then call each section individually. Here is the code I found, but how can I call each section (i.e. [0],[1],[2], etc.)?

 

<?php
// define string
$str = “The mice jumped over the cat, giggling madly ?
as the moon exploded into green and purple confetti”;

// define chunk size
$chunkSize = 11;

// split string into chunks
// result: [0] = The mice ju [1] = mped over t [2] = he cat, gig
// [3] = gling madly …
$chunkedArr = str_split($str, $chunkSize);
print_r($chunkedArr);
?>

Link to comment
https://forums.phpfreaks.com/topic/116153-break-text-into-chunks/
Share on other sites

<?php
require( $_SERVER['DOCUMENT_ROOT']."/configs/connection.php");
?>
<font style="font-size: 0.7em;" face="Tahoma">
<?php
$str = file_get_contents("http://".$_SERVER['HTTP_HOST']."/text/about_us.txt");
$chunkSize = 400;
$chunkedArr = str_split($str, $chunkSize);
$about_us0 = print_r($chunkedArr[0]);
?>
<?=$about_us0?><br>

 

This sends back the first 400 results AND adds a numeral 1 to the end. Anyone know why that is?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.