note 101870 added to function.array-slice
| From: | matthew dot a dot hawker at gmail dot com | Date: | Fri, 14 Jan 2011 22:30:40 +0000 |
| Subject: | note 101870 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175771@lists.php.net to get a copy of this message | ||
to yuwas at ht dot cx
As you asked, yes there is a better way to preset length
<?php
function str_slice($string,$offset,$length=null,$preserve_keys=False){
if( $length === null ){ $length = strlen($string)-$offset; }
$slice_arr = array_slice(str_split($string),$offset,$length,$preserve_keys);
return implode($slice_arr);
};
?>
Although, this is a very resource intensive way of doing this. Why not just use substr?
----
Server IP: 69.147.83.197
Probable Submitter: 213.49.255.121
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/101870
Del: integrated -- https://master.php.net/note/delete/101870/integrated
Del: useless -- https://master.php.net/note/delete/101870/useless
Del: bad code -- https://master.php.net/note/delete/101870/bad+code
Del: spam -- https://master.php.net/note/delete/101870/spam
Del: non-english -- https://master.php.net/note/delete/101870/non-english
Del: in docs -- https://master.php.net/note/delete/101870/in+docs
Del: other reasons-- https://master.php.net/note/delete/101870
Reject -- https://master.php.net/note/reject/101870
Search -- https://master.php.net/manage/user-notes.php