<?php
// tidy_example.php
// Using tiday
// RJM Programming - March, 2022 - Thanks to https://www.php.net/manual/en/function.tidy-warning-count.php

$there=true;
$html = '<p>test</i>
<bogustag>bogus</bogustag>';

if (isset($_GET['yourhtml'])) {
  $html=str_replace('+',' ',urldecode($_GET['yourhtml']));
} else if (isset($_POST['yourhtml'])) { 
  $html=str_replace('+',' ',urldecode($_POST['yourhtml']));
}

if (function_exists('tidy_parse_string')) {
try {
$tidy = tidy_parse_string($html);
} catch (Exception $ex) {
$there=false;
} 
} else {
$there=false;
}

//echo tidy_error_count($tidy) . "\n"; //1
//echo tidy_warning_count($tidy) . "\n"; //5
if (!$there && strpos($_SERVER['SERVER_NAME'], 'localhost') === false) {
echo "<html><head><title>Using tidy</title></head><body><h1>Using tidy</h1><h2>RJM Programming - March, 2022 - Thanks to <a target=_blank href=https://www.php.net/manual/en/function.tidy-warning-count.php>https://www.php.net/manual/en/function.tidy-warning-count.php</a><table style=width:95%;><tr><th>Mac OS X or macOS MAMP</th></tr><tr><tr><td><form target=_self method=GET action=HTTP://localhost:8888/tidy_example.php><textarea style=width:90%;height:200px;background-color:#f0f0f0; id=yourhtml name=yourhtml>" . $html . "</textarea><br><br><input style=background-color:yellow; type=submit value=Validate></input></form></td></tr><tr><th>Windows MAMP</th></tr><tr><tr><td><form target=_self method=GET action=HTTP://localhost/tidy_example.php><textarea style=width:90%;height:200px;background-color:#f0f0f0; id=yourhtml name=yourhtml>" . $html . "</textarea><br><br><input style=background-color:yellow; type=submit value=Validate></input></form></td></tr></table></body></html>";
} else {
echo "<html><head><title>Using tidy</title></head><body><h1>Using tidy</h1><h2>RJM Programming - March, 2022 - Thanks to <a target=_blank href=https://www.php.net/manual/en/function.tidy-warning-count.php>https://www.php.net/manual/en/function.tidy-warning-count.php</a><h3>" .tidy_error_count($tidy) . " errors</h3><h4>" . tidy_warning_count($tidy) . " warnings</h4><form id=myform method=POST action=./tidy_example.php><textarea style=width:90%;height:300px;background-color:#f0f0f0; id=yourhtml name=yourhtml>" . $html . "</textarea><br><br><input style=background-color:yellow; type=submit value=Validate></input></form></body></html>";
}
?>