note 41452 added to function.substr
| From: | webmaster at mytag dot org | Date: | Sat, 10 Apr 2004 13:30:59 +0000 |
| Subject: | note 41452 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67958@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41452
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41452&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41452&report=yes
Search -- http://master.php.net/manage/user-notes.php