jaxdevil Posted July 23, 2008 Share Posted July 23, 2008 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 More sharing options...
jaxdevil Posted July 23, 2008 Author Share Posted July 23, 2008 never mind. I figured it out: print_r($chunkedArr[0]); Link to comment https://forums.phpfreaks.com/topic/116153-break-text-into-chunks/#findComment-597312 Share on other sites More sharing options...
jaxdevil Posted July 23, 2008 Author Share Posted July 23, 2008 <?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 https://forums.phpfreaks.com/topic/116153-break-text-into-chunks/#findComment-597330 Share on other sites More sharing options...
ignace Posted July 23, 2008 Share Posted July 23, 2008 because you print_r() it all you need to do is: $about_us0 = $chunkedArr[0]; // will give you the first part print_r() is to loop over an array recursively notice the r in print_r Link to comment https://forums.phpfreaks.com/topic/116153-break-text-into-chunks/#findComment-597342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.