How can I append cutText function with dot leaders?

7 posts by 3 authors in: Forums > CMS Builder
Last Post: January 5, 2010   (RSS)

By Deborah - January 2, 2010

I am using a cutText function found on this forum to limit the number of characters in a WYSIWYG field. Because the WYSIWYG content automatically generates a closing </p> tag, I am unable to append a dot leader and "more" link such as this at the end of the snipped text:
<p>WYSISYG content blah, blah, blah ... <a href="#">more info</a></p>

Is there a modification I can do to the following existing code to accomplish this?
My code is as follows:

<head>
<?php function cutText($string, $setlength) {
$length = $setlength;
if($length<strlen($string)){
while (($string{$length} != " ") AND ($length > 0)) {
$length--;}
if ($length == 0) return substr($string, 0, $setlength);
else return substr($string, 0, $length);}
else return $string; }
?

<body>
<?php echo cutText($record['content'], 100); ?>

Thanks in advance for any help.
Deborah

Re: [Deborah] How can I append cutText function with dot leaders?

Hi Deborah,

The approach to link to the complete article could be something as simple as
<a href="<?php echo $record['_link']; ?>... Read More</a>

There are also some ideas in the posts returned by forum searches for the complete phrases read more and word count.

Good luck with this

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] How can I append cutText function with dot leaders?

By Deborah - January 3, 2010

Hi, Jerry.

Thanks for you post. Your suggestion works fine when the field is a textfield or textbox. However, a WYSIWYG field automatically ends with a closing paragraph tag, so there's no way I know of to append content *before* that closing tag, which is what I'd like to do.

I'm thinking that it would be necessary to modify the cutText function, but I'm sadly not a PHP whiz.

Thanks again for your help.
Deborah

Re: [Deborah] How can I append cutText function with dot leaders?

Life sure does get complex doesn't it.

Have a look at:

http://www.interactivetools.com/forum/gforum.cgi?post=63416#63416

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Deborah] How can I append cutText function with dot leaders?

By Chris - January 5, 2010

Hi Deborah,

I think the problem is that the cutText() function is (sometimes) stripping off the </p>. With no </p>, the preg_replace() can't find the right place to add the ...

For consistency, I'd recommend stripping the </p> off first, then calling cutText(), then adding your read more link, and finally replacing the </p>:

<?php
$html = preg_replace("|</p>\s*$|i", "", $record['content'] );
$html = cutText($html, 90);
$html = $html . "...</p>";
echo $html;
?>


Does that do what you want? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] How can I append cutText function with dot leaders?

By Deborah - January 5, 2010

Hi, Chris.

The suggested code works great!

Thanks so much for your help.

Deborah