note 68151 deleted from ref.tidy by cmb

From: Date: Sun, 21 Oct 2018 16:38:48 +0000
Subject: note 68151 deleted from ref.tidy by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209486@lists.php.net to get a copy of this message
Note Submitter: info att tcknetwork doot com ---- I have been searching for an easy way to check an entire website against HTML/XHTML formatting (no error, compilant, etc.), tidy is very useful for that : <?php /** aready checked pages */ $e=array(); /** webpages to check */ $t=array("/web/test.com/"); /** forbidden extensions (typically linked ressources) */ $x=explode(",","jpg,gif,png,doc,xls,pdf"); echo "<pre>"; while ($t[0]) { // already checked or a ressource => skip if (in_array($t[0],$e) || in_array(substr($t[0],-3),$x)) array_shift($t); else { $c=array_shift($t); $e[]=$c; $t=array_merge($t,ck($c)); } } echo "</pre>"; /** check_vailidty($url,$server) return : list of the internal links of the page */ function ck($u,$s="http://127.0.0.1") { $c=array("indent"=>1,"output-xhtml"=>1,"accessibility-check"=>3); $t=tidy_parse_string(file_get_contents($s.$u),$c); tidy_clean_repair($t); if (tidy_error_count($t)) { // we have error, display them echo "FAIL ".htmlentities($u)." (".tidy_error_count($t)." errors)\n"; echo htmlentities(tidy_get_error_buffer($t))."\n"; } else { // all right echo "OK ".htmlentities($u)."\n"; } // return all the links inside the page return gl(tidy_get_root($t),substr($u,-1)=="/"?$u:dirname($u)."/"); } /** get_links($tinynode,$baseurl) return : list of the links */ function gl($t,$b) { $r=array(); $c=count($t->child); for ($i=0;$i<$c;$i++) { $e=&$t->child[$i]; if ($e->name=="a") { // a link $h=$e->attribute["href"]; // url if (substr($h,0,4)!="http") { // prevent external links $r[]=sp(substr($h,0,1)=="/"?$h:$b.$h); } } else { // not a link, search recursively inside $r=array_merge($r,gl($e,$b)); } } return $r; } /** simplify_path($path) return : simplified path */ function sp($p) { while ($o!=$p) { $o=$p; $p=str_replace(array("//","/./"),"/",$p); $p=preg_replace("/\/[^\/]+\/..\//","/",$p); } return $p; } ?> Limitation : does not detect javascript-generated links. Check about set_time_limit(0) if you have a lot of webpages.

« previous php.notes (#209486) next »