Can you help me with strip_tags and strlen

They have: 22 posts

Joined: Oct 2008

I'm trying to trim a html text to an exact lenght.
I'm ussing strip_tags and strlen on the front page of jabulela but the text length is not always the same.
How to trim to an exact html lenght?
do you know any snippets ?

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

As long as you strip the tags before getting the string length, you should have no problem getting the proper length that matches all the others.

They have: 22 posts

Joined: Oct 2008

I strip tags before before getting the string length, but the problem is in the character length in pixels, or so I think, and I don't know how to solve this.

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Oh, ok. So you are looking to get a string width in pixels? PHP does offer the ability to get the dimensions of a string in pixels, using the imagettfbbox() function, but that is only for overlaying text on a graphic.

He has: 629 posts

Joined: May 2007

The only way I know to get the size of text on the screen is by using JavaScript. The fonts in your font stack are of different sizes, affecting the number of characters in a line. In addition, there are many settings of both the browser and the computer that affect text size. I don't think there's a way of detecting such settings with PHP.

Even with JavaScript it is tricky, as you need to put the text in a shrink-wrapped container to measure any particular piece of text. Then you have to monitor continuously for changes to browser text size settings.

Can you describe what you hope to achieve, exactly?

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

They have: 22 posts

Joined: Oct 2008

To print 3 lines of content with html tags included. If I cut too much sometimes are printed 2 lines, if I increase that value sometimes 4 lines are printed.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.