By zeta1600 on
I am using this snippet: http://drupal.org/node/283830 to create an auto node title using the first few words from the body. But, when adding apostrophe or quotes to words, it shows up in the title field as '.
I also found this: http://drupal.org/node/369694#comment-4644094 to remove the code in the field, but I can't figure out how to put it together. I tried the following, but it didn't work:
UPDATE: The code below seemed to work by combining the two like this:
<?php
$limit = 10;
$text = $node->body[$node->language][0]['value'];
$text = strip_tags($text);
$words = str_word_count($text, 2);
$pos = array_keys($words);
if (count($words) > $limit) {
$text = htmlspecialchars_decode($text, ENT_QUOTES);
$text = substr( $text, 0, $pos[$limit]);
$text = trim( $text );
$text = rtrim( $text, '.' );
$text = trim( $text ) . '...';
}
return $text;
?>