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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.