* Erik Meyer <[EMAIL PROTECTED]>: > I have a function loosely based on the following tutorial from zend.com. > (http://www.zend.com/zend/tut/tutorial-brogdon2.php) > However, instead of using plain-text I am using results with html tags. > > For example, the results may have <b>This</b>is some text that has been > inputted from a form. When I use my function it simply takes this string > and counts the number of words and then stops at a length desired and > returns the text. Now, here is my problem. If I don't call my function it > displays fine, but I have to display the entire result since I do not want > to stop in the middle of a word. If I call my function it displays the > summary correctly if there are no html tags in it. However, if I call my > function and there are html tags then it strips the < > off of the html tag > and displays the text in between the angle brackets. > > Here is my function (forgive me if I am taking the wrong way this is my baby > step at php) > > If anybody has a better way I would appreciate it,
I can think of a number of them. 1) pipe your results through striptags() to remove all HTML formatting *before* you shorten the string 2) use a templating engine. Smarty has some incredible functions such as truncate() which can not only take care of the HTML formatting but also make sure that truncation ends with a word or sentence boundary 3) look at code such as the above-mentioned Smarty to see how others have successfully resolved this. I use (2) with a number of systems, and love it. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php