0

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...

1 Answers1

0

There are 2 mistakes:

  1. $word=Hello World; should be $word='Hello World';
  2. 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];
?>
Razvan Zamfir
  • 4,209
  • 6
  • 38
  • 252