note 101870 deleted from function.array-slice by danbrown

From: Date: Fri, 14 Jan 2011 22:31:37 +0000
Subject: note 101870 deleted from function.array-slice by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175772@lists.php.net to get a copy of this message
Note Submitter: matthew dot a dot hawker at gmail dot com ---- 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?

« previous php.notes (#175772) next »