PHP Tidy class not found, error

Roberto Rizzi picture Roberto Rizzi · Jan 29, 2014 · Viewed 12.7k times · Source

I was writing some code for repair html string. I read some nice solutions which work with the Tidy PHP class but I had some troubles with it. What in this post is written, is exactly what I want but I need to install / load the PHP Tidy class. Close tags from a truncated HTML string

I'm working on PHP 5.5.4. I tried to install tidy following some tutorials but nothing has append. When I call the tidy class $tidi = new \tidy();, NetBeans suggests me the class and clicking on it (Ctrl + click) I see it but refreshing the page I obtain the error Class 'tidy' not found in ... /myfile.php line ...

I used in the same way the class $myVar = new \DomDocument(); but it works perfectly.

Checking whether the Tidy extension is loaded like below, I get "NOT LOADED".

echo extension_loaded('tidy') ? "LOADED" : "NOT LOADED";

Please, can someone explain me how Tidy works and how can I set it up? My Ubuntu's version is 13.10.

Answer

ToBe picture ToBe · Jan 29, 2014

Your php.ini contains a list of "extension=somefile.so" lines. You are missing the correct line for your tidy extension. It should be included but commented in your file. Just remove the ; character in front of the one line for the tidy extension and restart your webserver.

Sample for windows:

extension=php_tidy.dll

Sample for Linux:

extension=tidy.so

On some Linux distribution, it has to be installed if you can't find the extension file tidy.so in your extensions folder. Execute the correct line depending on your distribution. You have to be root or use sudo:

CentOS/RedHat (replace with correct lib as found via yum search php-tidy:

yum install rh-php56-php-tidy.x86_64

Debian/Ubuntu:

apt-get install php5-tidy