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: [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: [Djulia] CMS Builder Search Engine

By Dave - January 13, 2008

You can use $record['content'] instead of $myValue.

When you see the @ symbol in front of something in PHP if means "don't show errors for that". So sometimes we'll use @$record['content'] so that if $record['content'] isn't defined we won't get a "undefined variable" warning message displayed on the screen by PHP.

Here's an updated function the replaces tags with a space when it removes them so the words don't get joined together.

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

Dave Edis - Senior Developer
interactivetools.com

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