Page 1 of 1

[SOLVED] Substring...

Posted: Wed Dec 20, 2006 6:00 am
by dethron
Labas to All :)
I want to cut a text after 400 charachers, and display it.
However since my text also contains some HTML codes, 400 may contain some unclosed HTML tags :(
If you have any basic ides, you are more than welcome.
Thnx...

Posted: Wed Dec 20, 2006 6:02 am
by onion2k
strip_tags() ?

Posted: Wed Dec 20, 2006 6:03 am
by dethron
kill tags :) who likes them. alright, i guess this is the optimized solution...

Posted: Wed Dec 20, 2006 6:12 am
by dibyendrah
You may want to get 400 characters without counting HTML chars.

Posted: Wed Dec 20, 2006 6:39 am
by dethron
Yes i also thought that but at the end again tags are problems :)

Let me give an example;

If you have a "<font>" tag at the start and after 1000chars "</font>" at the end.

Some how you have to add all the tags after 400chars to supply consistency.

So it is better to remove tags ;)

Posted: Thu Dec 21, 2006 12:17 am
by dibyendrah
Excluding the HTML characters and counting required characters can be done by converting HTML chars to HTML special chars. While counting each characters, just ignore those HTML special characters.but taking those special characters and not counting them. I think that can be achieved using regular expression.