Re: [PHP] Trimming Text

2005-07-17 Thread Ben-Nes Yonatan

André Medeiros wrote:

On Fri, 2005-07-15 at 16:03 +0100, Richard Davey wrote:


Hello André,

Friday, July 15, 2005, 4:24:23 PM, you wrote:

AM I am trying to trim some text containing HTML tags. What I want to
AM do is to trim the text without trimming the tags or html entities
AM like nbsp; and such, wich completelly break the design.

The problem as I see it, is that while it's easy to trim some text and
then check to see if you were inside an HTML tag or not, it becomes
MUCH harder to check if you were inside nested tags (for example
strongem)

If there are no nested tags then it's much easier.. just trim the
string at X characters and then search for the last occurrence of a
'' and the last occurance of '' - if the first is LESS than the second
value, then you're in the middle of a tag.

This of course doesn't handle nested tags.

Best regards,

Richard Davey
--
http://www.launchcode.co.uk - PHP Development Services
I do not fear computers. I fear the lack of them. - Isaac Asimov




Yeah... that's the point :( Nested tags are very possible.

I am not sure how one would go here tho



sorry that i didnt have time to read everything word by word but did you 
try to run strip_tags()?


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



RE: [PHP] Trimming Text

2005-07-15 Thread Jay Blanchard
[snip]
I am trying to trim some text containing HTML tags. What I want to do is
to trim the text without trimming the tags or html entities like nbsp;
and such, wich completelly break the design.

Has anyone succeded on doing such a thing? phpclasses.org won't help :(
[/snip]

What do you mean, trim some text containing HTML tags? Can you give us
some examples of what you are starting with and what you'd like to end
up with?

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



Re: [PHP] Trimming Text

2005-07-15 Thread Raz
Take a look at http://uk.php.net/manual/en/ref.pcre.php - plenty of
useful functions for this sort of thing...

raz

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



Re: [PHP] Trimming Text

2005-07-15 Thread André Medeiros
On Fri, 2005-07-15 at 15:40 +0100, Raz wrote:
 Take a look at http://uk.php.net/manual/en/ref.pcre.php - plenty of
 useful functions for this sort of thing...
 
 raz

Implementing regular expressions on this kind of task would be a big
PITA... and that's if it works (read my previous e-mail).

Thanks for the suggestion anyway :)

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



Re: [PHP] Trimming Text

2005-07-15 Thread Raz
Are you trying to turn, for example

p Some text here. /p

into

pSome text here./p

?

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



Re: [PHP] Trimming Text

2005-07-15 Thread André Medeiros
On Fri, 2005-07-15 at 15:49 +0100, Raz wrote:
 Are you trying to turn, for example
 
 p Some text here. /p
 
 into
 
 pSome text here./p
 
 ?

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

This is regular text span class=textwith 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.

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



RE: [PHP] Trimming Text

2005-07-15 Thread Jay Blanchard
[snip]
Let's say that I have an original string like:

This is regular text span class=textwith 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=textwith 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



Re: [PHP] Trimming Text

2005-07-15 Thread Richard Davey
Hello André,

Friday, July 15, 2005, 4:24:23 PM, you wrote:

AM I am trying to trim some text containing HTML tags. What I want to
AM do is to trim the text without trimming the tags or html entities
AM like nbsp; and such, wich completelly break the design.

The problem as I see it, is that while it's easy to trim some text and
then check to see if you were inside an HTML tag or not, it becomes
MUCH harder to check if you were inside nested tags (for example
strongem)

If there are no nested tags then it's much easier.. just trim the
string at X characters and then search for the last occurrence of a
'' and the last occurance of '' - if the first is LESS than the second
value, then you're in the middle of a tag.

This of course doesn't handle nested tags.

Best regards,

Richard Davey
-- 
 http://www.launchcode.co.uk - PHP Development Services
 I do not fear computers. I fear the lack of them. - Isaac Asimov

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



Re: [PHP] Trimming Text

2005-07-15 Thread Raz
If you really want to do it, you're gonna have to get your hands
dirty, I'm afraid...;)

...off with the gloves...!

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



Re: [PHP] Trimming Text

2005-07-15 Thread André Medeiros
On Fri, 2005-07-15 at 16:12 +0100, Raz wrote:
 If you really want to do it, you're gonna have to get your hands
 dirty, I'm afraid...;)
 
 ...off with the gloves...!

I was affraid that would happen :(

Thanks anyway :)

Take care!

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



RE: [PHP] Trimming Text

2005-07-15 Thread André Medeiros
On Fri, 2005-07-15 at 10:02 -0500, Jay Blanchard wrote:
 [snip]
 Let's say that I have an original string like:
 
 This is regular text span class=textwith 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=textwith som
 e text inside a span/sp
 an
 
 ?

I am wanting to

This is regular text sp... (see more)

;)

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



RE: [PHP] Trimming Text

2005-07-15 Thread tg-php
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=textwith 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 withsnip

Then output as:
This is regular text span class=textwith/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=textwith 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=textwith 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



Re: [PHP] Trimming Text

2005-07-15 Thread André Medeiros
On Fri, 2005-07-15 at 16:03 +0100, Richard Davey wrote:
 Hello André,
 
 Friday, July 15, 2005, 4:24:23 PM, you wrote:
 
 AM I am trying to trim some text containing HTML tags. What I want to
 AM do is to trim the text without trimming the tags or html entities
 AM like nbsp; and such, wich completelly break the design.
 
 The problem as I see it, is that while it's easy to trim some text and
 then check to see if you were inside an HTML tag or not, it becomes
 MUCH harder to check if you were inside nested tags (for example
 strongem)
 
 If there are no nested tags then it's much easier.. just trim the
 string at X characters and then search for the last occurrence of a
 '' and the last occurance of '' - if the first is LESS than the second
 value, then you're in the middle of a tag.
 
 This of course doesn't handle nested tags.
 
 Best regards,
 
 Richard Davey
 -- 
  http://www.launchcode.co.uk - PHP Development Services
  I do not fear computers. I fear the lack of them. - Isaac Asimov
 

Yeah... that's the point :( Nested tags are very possible.

I am not sure how one would go here tho

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



Re: [PHP] Trimming text

2002-04-24 Thread Miguel Cruz

On Wed, 24 Apr 2002, Ashley M. Kirchner wrote:
 I have a variable ($description) that contains text data (pulled from an MySQL 
DB).  I need to delete the last few lines from that data.  Prior to the data getting 
submitted to the DB (during a different routine), the following information gets 
added:
 
 $description .= \n\n span class=gensmall Modified by .$userdata[username]. 
/span .;
 (spaces added so the tags don't get parsed)
 
 Later in the routine, that data gets pulled back up for modification and I need 
to delete that last bit from it.  From the starting '\n' till the end ' /span .'...
 
 What's the best, and or easiest way to do this?

Someone else has already provided you with a regex. I'll provide you with
a new question: Why store it that way? Just create a new field to hold the
name of the user who last modified the description. Then you don't have to
do all that processing, and you aren't unnecessarily intermingling
formatting with data.

miguel


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




Re: [PHP] Trimming text

2002-04-24 Thread Ashley M. Kirchner

Miguel Cruz wrote:

 Someone else has already provided you with a regex. I'll provide you with
 a new question: Why store it that way? Just create a new field to hold the
 name of the user who last modified the description. Then you don't have to
 do all that processing, and you aren't unnecessarily intermingling
 formatting with data.

Because I didn't originally write the script that does it, and at this point in 
the game, it's easier to just strip the data, than it is to rewrite the whole code, 
and redo the database.  A database that already contains information too.

--
H | Life is the art of drawing without an eraser. - John Gardner
  +
  Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
  Director of Internet Operations / SysAdmin. 800.441.3873 x130
  Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave, #6
  http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.



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