RE: Trimming Text

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

 



Sounds like maybe he wants to keep his output to 25 chars not including HTML tags.. but wants to output tags if they're present.

Turn this:
This is regular text <span class="text">with some text inside a span</span>

Into this:
This is regular text with some text inside a span

Then trim to:
This is regular text with<snip>

Then output as:
This is regular text <span class="text">with</span>


In that case I'd do the following:

1. Use html_entity_decode and strip_tags to get just the text you want
2. Trim the text to the length you want
3. Somehow figure out where the HTML tags are in the original text and put them back, also use htmlentities to change any special characters back to entities.


Someone might have a clever way of figuring out where the HTML tags are supposed to go back.  I don't know of any quick and dirty way to do it off the top of my head.

-TG




= = = Original message = = =

[snip]
Let's say that I have an original string like:

This is regular text <span class="text">with some text inside a
span</span>

Let's say I want to trim it to 25 chars.

"Brainless trimming" would give me something like

"This is regular text <sp"

Wich would completelly mess the design.

However, if I finish the tag, the following text will be formatted by
the <span class="text"> tag, thus messing the design also.

It also happened to trim &nbsp; to half, having the same effect.

I want to find a smart way to do this trimming in order not to have any
side effects.
[/snip]

Trim it to 25 characters? I think we may be missing the point of your
question. Can you clarify this for us? Are you wanting....

This is regular text <sp
an class="text">with som
e text inside a span</sp
an>

?

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


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.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