note 81866 added to function.substr
| From: | Anonymous at osu1 dot php dot net | Date: | Mon, 17 Mar 2008 11:53:49 +0000 |
| Subject: | note 81866 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137120@lists.php.net to get a copy of this message | ||
Split a string to an array of strings specified by an array of lengths:
<?php
function split_by_lengths($inString, $arrayLengths)
{
$output = array();
foreach ($arrayLengths as $oneLength)
{
$output[] = substr($inString, 0, $oneLength);
$inString = substr($inString, $oneLength);
}
return ($output);
}
?>
split_by_lengths('teststringtestteststring', array(4,6,4,4,6)) returns:
array('test','string','test','test','string')
Don't use it on user input without some error handling!
----
Server IP: 83.170.119.58
Probable Submitter: 87.224.36.206
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/81866
Del: integrated -- https://master.php.net/note/delete/81866/integrated
Del: useless -- https://master.php.net/note/delete/81866/useless
Del: bad code -- https://master.php.net/note/delete/81866/bad+code
Del: spam -- https://master.php.net/note/delete/81866/spam
Del: non-english -- https://master.php.net/note/delete/81866/non-english
Del: in docs -- https://master.php.net/note/delete/81866/in+docs
Del: other reasons-- https://master.php.net/note/delete/81866
Reject -- https://master.php.net/note/reject/81866
Search -- https://master.php.net/manage/user-notes.php