note 110904 added to function.str-split

From: Date: Fri, 21 Dec 2012 10:29:05 +0000
Subject: note 110904 added to function.str-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-192628@lists.php.net to get a copy of this message
An easy way to split long texts in columns/pages with entire last words $text = "This is a very very long text ... the end"; // ie 7000 cars. $max_car = 1500; // content length of each page/col // we first split the text in equal parts $pages = str_split($text, $max_car); // we now get something like // $pages 1 = "This is a .... very long te" // $pages 2 = "xt but first/last words are cutted" // we now find each last whitespace of each col/page foreach ($pages as $content) { $content = $report.$content; //add the reported cars of previous page (ie "te" to get "text" on page2) $last_space = strrpos($content," "); $page = substr($content,0,$last_space); $report = str_replace($page,'',$content); // reported cars // we now get // $pages 1 = "This is a .... very long" // $pages 2 = "text and first/last words are OK" echo $page; } ---- Server IP: 69.147.83.199 Probable Submitter: 90.26.175.97 ---- Manual Page -- http://php.net/manual/en/function.str-split.php Edit -- https://master.php.net/note/edit/110904 Del: integrated -- https://master.php.net/note/delete/110904/integrated Del: useless -- https://master.php.net/note/delete/110904/useless Del: bad code -- https://master.php.net/note/delete/110904/bad+code Del: spam -- https://master.php.net/note/delete/110904/spam Del: non-english -- https://master.php.net/note/delete/110904/non-english Del: in docs -- https://master.php.net/note/delete/110904/in+docs Del: other reasons-- https://master.php.net/note/delete/110904 Reject -- https://master.php.net/note/reject/110904 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192628) next »