Re: [PHP] generating an html intro text ...



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
.



Relevant Pages

  • Re: Please help:need to read XML, edit, and write back to XML file
    ... I copied Astrid's code into a VBA module and ran it, ... give me any of the tags. ... string, as the scripting code gave me. ... reading, writing or appending. ...
    (microsoft.public.word.vba.general)
  • RE: [PHP] Need help with RegEx
    ... The End of string symbol ^ should not be included. ... I want what is inside the tags. ... fifth atom = all of the rest of the source html after the closing ...
    (php.general)
  • Re: Removing html tags from field
    ... I just remembered - you want to replace the tags with a space or something. ... Public Function KillHTML(sText As String, ... Dim iRight As Integer ... > Is there a way to remove html tags from a memo field? ...
    (microsoft.public.access.queries)
  • Re: Please help:need to read XML, edit, and write back to XML file
    ... And it's perfect - it puts everything in a string with all the tags, ... of the code can be used in a VBA routine. ... the information in the various forms and generates an XML file. ...
    (microsoft.public.word.vba.general)
  • Re: HTML doc save dialog
    ... After getting the string from database do not set the string to ... > and end html tags. ... In the document complete event of browser, ...
    (microsoft.public.dotnet.languages.csharp)