How to get text only summary of field

8 posts by 2 authors in: Forums > CMS Builder
Last Post: January 13, 2008   (RSS)

By Djulia - January 12, 2008 - edited: January 13, 2008

Hi Dave,

I have just made the update and that functions correctly now. [:)]

Another question.

You think that it is possible to obtain a short content ?
And also to delete the paragraphs ?

For example:

Duis pede enim, aliquet ac, luctus nec, aliquet a, lorem.

Aenean ultrices sem fermentum velit. Nam nisi enim, posuere at, suscipit eu, rutrum eu, diam.
Praesent a enim eget nulla condimentum viverra. Nunc diam dolor, ultrices in, commodo ut, dictum consectetuer, nisi. Mauris dolor lorem, nonummy mollis, blandit non, fringilla blandit, nulla.

Mauris nec nibh eu purus semper ullamcorper. Ut quis ipsum. Donec sagittis mattis velit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean semper velit. Sed tincidunt auctor diam. Vivamus in massa.

For:

Duis pede enim, aliquet ac, luctus nec, aliquet a, lorem. Aenean ultrices sem fermentum velit. Nam nisi enim, posuere at, suscipit eu, rutrum eu, diam. Praesent a enim eget nulla condimentum viverra. ...

--


Thank you for your answer.

Djulia

Re: [Djulia] CMS Builder Search Engine

By Dave - January 12, 2008

>You think that it is possible to obtain a short content ?
>And also to delete the paragraphs ?


Yes, it's a PHP question. Here's a function that removes all the html tags, then returns the first NNN number of words:

// remove all tags and reutnr first NNN words of content
function getTextSummary($value, $maxWords = 25) {
$textOnly = strip_tags($value);
$words = preg_split("/\s+/", $textOnly);
$words = array_splice($words, 0, $maxWords);
$summary = join(" ", $words);
return $summary;
}


It defaults to returning 25 words and you can change the default above or specify how many words you want. Like this:

$myValue = "Aenean ultrices sem fermentum velit. Nam
nisi enim, posuere at, suscipit eu, rutrum eu, diam.
Praesent a enim eget nulla condimentum viverra. Nunc diam
dolor, ultrices in, commodo ut, dictum consectetuer, nisi.
Mauris dolor lorem, nonummy mollis, blandit non, fringilla
blandit, nulla. ";

print getTextSummary($myValue); // returns 25 words

print getTextSummary($myValue, 6); // returns 6 words


Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] CMS Builder Search Engine

By Djulia - January 13, 2008

Excuse my ignorance.

But, it is possible to obtain : $myValue = "$record['content']";

Thank you for your assistance.

Djulia

Re: [Djulia] CMS Builder Search Engine

By Djulia - January 13, 2008

That functioned : $myValue = @$record['content'];

You confirm ?

Thank,
Djulia

Re: [Dave] CMS Builder Search Engine

By Djulia - January 13, 2008 - edited: January 13, 2008

I have another problem.

In the table, the return to the line (<br />) gives attached words.

For example :

Aenean ultrices sem<br />fermentum velit.<br />Nam nisi enim,<br />posuere at, suscipit<br />eu, rutrum eu, diam.

give :

Aenean ultrices semfermentum velit.Nam nisi enim,posuere at, suscipiteu, rutrum eu, diam.

---

You have an idea ?

Thank you our your answer.

Djulia

Re: [Dave] CMS Builder Search Engine

By Djulia - January 13, 2008 - edited: January 13, 2008

Thank you Dave, it is perfect ! [:)]

I also added to the end : print(" ...");

<?php
$record['content'];
print getTextSummary($record['content'], 40); // returns 25 words
print (" ...");
?>

Djulia

Re: [Djulia] CMS Builder Search Engine

By Dave - January 13, 2008

Looks good! :)

By the way, would you be able to add your hosting provider to our supported hosts page: http://www.interactivetools.com/forum/gforum.cgi?post=58865

Thanks!
Dave Edis - Senior Developer
interactivetools.com