note 75595 added to function.array-slice
| From: | cpa at NOSPAM dot conceptivator dot com | Date: | Thu, 07 Jun 2007 12:15:31 +0000 |
| Subject: | note 75595 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127266@lists.php.net to get a copy of this message | ||
'gportlock at gembiz dot co dot uk' has an error in his limitText function. It simply
takes a text string, then cuts off the first X words and returns the rest of the string. I believe
the intended use is to return only the first X words and cut off the rest.
The correct version should be (notice the inserted 0 offset):
<?php
function limitText( $text, $wordCount )
{
$wordArray = explode(" ", $text);
array_splice($wordArray, 0, $wordCount);
return implode( " ", $wordArray );
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 90.184.87.230
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/75595
Del: integrated -- https://master.php.net/note/delete/75595/integrated
Del: useless -- https://master.php.net/note/delete/75595/useless
Del: bad code -- https://master.php.net/note/delete/75595/bad+code
Del: spam -- https://master.php.net/note/delete/75595/spam
Del: non-english -- https://master.php.net/note/delete/75595/non-english
Del: in docs -- https://master.php.net/note/delete/75595/in+docs
Del: other reasons-- https://master.php.net/note/delete/75595
Reject -- https://master.php.net/note/reject/75595
Search -- https://master.php.net/manage/user-notes.php