[SOLVED] Substring...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

[SOLVED] Substring...

Post 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...
Last edited by dethron on Wed Dec 20, 2006 6:04 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

strip_tags() ?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

kill tags :) who likes them. alright, i guess this is the optimized solution...
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

You may want to get 400 characters without counting HTML chars.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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 ;)
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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.
Post Reply