|
-
Aug 28th, 2006, 11:19 PM
#1
Thread Starter
Lively Member
Auto-close HTML tags using PHP
Hi everyone,
Is anyone aware of a function or other bit of code that could quickly and easily close open HTML tags.
We're looking at this for a forum-type situation where members are permitted to use HTML in their messages, however sometimes forget to close the tags and muck up the rest of the page layout. e.g. <b>Hi, I forgot to close the bold tag...doh!
Any ideas greatly appreciated, I've had a hunt around but haven't found anything yet - still searching.
-
Aug 28th, 2006, 11:43 PM
#2
Re: Auto-close HTML tags using PHP
That's one of the reasons why BB code was invented.
If you are bent on allowing HTML, one thing you could do is parse the message into a DOM tree (using the DOMDocument class) and see if it is well-formed; if it isn't then you can show the user a message and not submit the post.
However, you really shouldn't let users post raw HTML anyway.
-
Aug 28th, 2006, 11:47 PM
#3
Thread Starter
Lively Member
Re: Auto-close HTML tags using PHP
Yeah I know, it's not my forum or code - was just trying to find a solution to a problem they're having. But I think the route will be BB code as you mentioned...
-
Aug 29th, 2006, 02:57 AM
#4
Re: Auto-close HTML tags using PHP
Use PHP 5 and use the loadHTML() method of the DOMDocument object. This auto parses badly formed HTML and a subsequent call to saveXML() will output the valid HTML. The DOM functions can be found here:
http://www.php.net/dom
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|