Skip to content | Skip to navigation
So I finally bought a webhosting package and am developing a site for my residence hall and myself (using the residence hall's site's code as my backend too). You can check out my page at http://www.terminalfuture.com/.
Now, for the "blog" entries on the front page, I have each return (they are stored in a mysql database) run through a function that checks the entry for length and trunicates it if it is over 1000 words. It does look out for special characters (you know, >, etc. etc.) and leaves them intact or removes them completely, however I was wondering if anyone knew of some code out there that does the same function however looks for open tags (like an open <p> tag) without its complimenting </P> tag and after the trunication fills in the complimenting closing tags.
I'd go through and code this myself since in all reality it isn't that hard of a quest, however since I am busy building other parts of the site, I can't justify going back and doing that since what I do currently works well enough.
I just want some predone code so I don't reinvent the wheel so to speak...
Pistol Grip Pump In My Lap At All Times
however I was wondering if anyone knew of some code out there that does the same function however looks for open tags (like an open <p> tag) without its complimenting </P> tag and after the trunication fills in the complimenting closing tags.
Give WordPress and its plugins a try. I've extracted several nice parts of them for using it in my own scripts, eg. the wpautop/nl2p function which automatically does replace normal line feeds with break- and p-tags (a replacement for nl2br).
Basically you'd have to do something like this (quick'n'dirty way):
1. Use strip_tags to strip out all unneeded html-tags - like this:
$return = strip_tags($my_text, '<a><strong><em><img>');
2. Now you can concentrate on the tags that are still available (in my example: anchor-, strong, em(phasize) and image-tag) and create a RegEx to cover them - according to php-documentation its better to use preg_match / preg_replace instead of eregi / eregi_replace (they say its faster and then, those functions are using PERL-based RegExes).
Another suggestion: Why dont you try using BBCode instead? Could reduce the code you have to look after a bit. ;)
That's to it right now - it's 06:45 in the morning, I'm not going to talk any further about this topic - I'm tired.
g'night,
cu, w0lf.
NP: Mad Sin - Underground
Fuck off the 30 seconds posting limit!
This post was edited by ginsterbusch on Oct 14, 2005.
eg. the wpautop/nl2p function which automatically does replace normal line feeds with break- and p-tags (a replacement for nl2br).
I use fckeditor to submit my entries so formatting is already taken care of. I'm basically building the residence hall website to be maintained by complete idiots, therefore a WYSIWYG editor for entries is as bout as idiot proof as it gets. I seriously wouldn't trust some of these guys to even BB code, plus I don't want to have to hang around after I've left.
Plus WYSIWYG editors are just plain cool :P
I will give WordPress's code a looksee, however.
That's to it right now - it's 06:45 in the morning, I'm not going to talk any further about this topic - I'm tired.
Sleep well my friend.
Pistol Grip Pump In My Lap At All Times