View Full Version : php-script with html-tidy functionality

09-16-2003, 10:06 PM

Some time ago I created a very light-weight cms system for a client of mine, so he can easily edit the content of his website. While editing the content he can add html tags as well.

To prevent the client from adding incorrect or 'ugly' html I'm looking for a tool that can check the input and can correct the html and/ or can convert it to valid xhtml.

I found an extension for php that will do exactly what I want (http://pear.php.net/package-info.php?package=tidy). The only problem with this extension is that it is only supported bij php 5.0, which I and my client don't have.

Now I'm looking for a php-script that will have the same, or similar, functionality, but is also supported by php 4. I doesn't really matter if it isn't as extensive as the package above, as long as it can convert the html to valid (x)html.

Does anyone know of such a project? Or does anyone know whether it's very hard to create something like this yourself?

Thanks in advance!


09-17-2003, 04:25 AM
Hi , I am doing something similar at the moment , but its not as straightforward as I was hoping :)

I am using the current XML parser functions to create an xml parser then look at each tag as it is parsed and try and fix known issues , some are easy some not , eg some require ridiculous regex and some just simple str_replace()ments.

The main problem I am having (aside from the regex) is that if there is say a mismatched tag in the html stream then the parser breaks , ok it gives an error which you can detect , then try and fix within the script and re-run the parser but endless loops seem to crop up quite easily and quickly :D

If I get any further then I will post here , until then have you checked out hotscripts or phpclasses.org ?

09-17-2003, 09:18 AM
Hi Firepages,

thanks for your reply. What I hear from you it isn't as easy as I thought it would be :D I'd like it if you could keep me posted on your progress!

I did in fact check out hotscript and phpclasses.org, but unfortunatelly I didn't get any results. As soon as I find something usefull I'll post it here as well!

Cheers, Michiel

09-17-2003, 09:22 AM
Maybe your host is so flexible to have tidy installed on the server, so you could call it with system(), shell_exec() or popen()? There's an example how to do this in the usernotes on http://us2.php.net/manual/en/ref.outcontrol.php

09-17-2003, 10:36 AM

that might be a good solution, though it isn't as flexible as I would like it to be. The thing is that I want to add this tool to other cms-systems, for other clients as well, who might not have a host that wants to install tidy on the server.

I will give it a shot though in this particular situation, but I'll keep looking for a php 4 solution!

Thanks Michiel

PS: did you notice that you've posted exactly 1100 posts more than I did (1189 vs 89), and you registered only 1 month earlier than I did? I think we can state that you are only a teeny-tiny bit more active than I am :thumbsup: