Question

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.

No correct solution

OTHER TIPS

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

I had the same issue and I finnally figured it out, this solution is for ubuntu 14.04 running xampp.

step 1
open terminal and input the following

sudo apt-get install php5-tidy

step 2
time to find out where "tidy.so" got installed to.


for me it was installed to "/usr/lib/php5/20121212/tidy.so"

step 3

find and open your php.ini file and find the extensions section and insert the following line

extension=/usr/lib/php5/20121212/tidy.so

step 4

go back to your terminal and run the following to restart your server.

sudo /opt/lampp/lampp restart

step 5

verifying that the new tidy module has been loaded by either

in terminal

php -m

and/or by creating a file on your server in the htdocs called test.php and inserting the following code

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

next run that test.php file in your browser and it should read "LOADED"

if not go back and review the previous steps until you get that message.

I hope this helps, :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top