note 50743 added to function.str-split

From: Date: Tue, 08 Mar 2005 17:09:15 +0000
Subject: note 50743 added to function.str-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-86115@lists.php.net to get a copy of this message
As this function is only available in php5, I had problems with it's availability, so i had to write my own. Here's the code: <?php function stringsplit($the_string, $the_number) { $startoff_nr = 0; $the_output_array = array(); for($z = 1; $z < ceil(strlen($the_string)/$the_number)+1 ; $z++) { $startoff_nr = ($the_number*$z)-$the_number; $the_output_array[] = substr($the_string, $startoff_nr, $the_number); } return($the_output_array); } $string = "so long and thanks for all the fish!"; $foo = stringsplit($string, 6); print($foo); ?> and this will output: Array ( [0] => so lon [1] => g and [2] => thanks [3] => for a [4] => ll the [5] => fish! ) what is exactly the same as str_split() 's output. hope this solves someones problems. ---- Manual Page -- http://www.php.net/manual/en/function.str-split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50743 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50743&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50743&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50743&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50743&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50743&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50743&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86115) next »