note 41452 deleted from function.substr by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 10 Apr 2004 15:39:27 +0000 |
| Subject: | note 41452 deleted from function.substr by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67962@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster@mytag.org
----
This function splits a string in n substrings.
<?php
############################
# piero06 - 2004
# function dividi();
# http://www.mytag.org
############################
function dividi($q,$str){
$parti = strlen($str)/$q;
$prim = 0;
$sec = $q;
for ($i=0;$i<$parti;$i++){
$par = $q*$i;
$par1 = $q*($i+1);
if ($i==0){
$ex[] = substr($str,$par,$par1);
}else{
$ex[] = substr($str,$par,$q);
}
$prim = $prim+$q;
$sec = $sec+$q;
echo $ex[$i]."<br>";
}
}
?>
Example :
<?php
$str = 'abcdefghi'; //string to split
$q = 5; //numer of chars of the new substrings
echo dividi($q,$str);
?>
OutPut :
abcde
fghi
Enjoy