This question already has an answer here:
Hello Guys I try to short the content of a post in a preview page. I have tried out the code and it doesn't work. It shows only an 'array' as text. Is this echo wrong or any other failures?
$word=Hello World;
$words = str_word_count($word, 1,'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ');
$len = min(50, count($words));
$first_fifty = array_slice($words, 0, $len);
echo $first_fifty;
Thanks for Help...
</div>
There are 2 mistakes:
$word=Hello World;
should be $word='Hello World';
You are echoing an array; do print_r ($first_fifty);
instead;
All the code:
<?php $word='Hello World'; $words = str_word_count($word, 1,'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'); $len = min(50, count($words)); $first_fifty = array_slice($words, 0, $len); print_r ($first_fifty); ?>
You can echo:
<?php
echo $first_fifty[0] . ' ' . $first_fifty[1];
?>