Re: generating an html intro text ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 11:39 AM +0200 6/14/07, Jochem Maas wrote:
original string:

"<b>HELLO</b>, my name is charlie brown<i>!</i> &amp; I'm a little odd.";

shorten text (32 'letters' required):

	"My name is <b>charlie brown</b><i>!</i> &amp; I'm ";

the 32 'letter' length should therefore ignore the B and I tags and treat the &amp; as a single letter ... additionally when truncation occurs with a set of html tags the
resulting string should have all the open html tags properly closed.

this is not as simple as it may first seem, I could probably do it but I foresee it taking quite some time (which I don't have ... let's all sing 'deadline' together shall we ;-)), in the past I have attempted such a routine but always ended up doing something much simpler
(using strip_tags(), etc) due to time constraints.


The problem as I see it is covering all the possibilities that may occur even if the text is well formed. Like what if someone introduces a span that sets a color for a paragraph, such as:

<span color:"yellow"; >Dolore magna aliquam erat volutpat ut wisi enim ad minim veniam quis nostrud. Consectetuer adipiscing elit sed diam nonummy nibh euismod tincidunt ut laoreet exerci tation ullamcorper suscipit lobortis! <b>Decima eodem modo </b>typi qui nunc nobis videntur parum clari fiant sollemnes in.<span>

And the </b> tag as well as the </span> tag is outside the 256 limit?

You would have to search out and pull in all closing tags.

So, I guess an algorithm could be:

First, grab 256 characters -- The string. If The string is shorter, then quit.

Second, determine what tags are not closed.

Third, create closing tags and add them to the end of The string (in proper order).

Fourth, then remove the same number of non-html characters from the end of The string.

OR, just strip out the html tags (strip_tags) and go with straight text -- a lot easier.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux