Valid XHTML    Valid CSS2    

Listing du fichier eltatt_inc.php

 

00001     <?php
00002     
# (gH) -_- eltatt_inc.php ; TimeStamp (unix) : 07 Février 2011 vers 18:37
00003     
00004     #############################################################################
00005     
00006     
function estW3Cvalide($uri) {
00007     
00008     
#############################################################################
00009     
00010      # est-ce que le fichier bien formé ? successfully checked
00011      # successfully checked / Errors found
00012      # [Valid] / [Invalid]
00013      #
00014      # <h2 id="results" class="invalid">Errors found while checking this document as HTML5!</h2>
00015      # <h2 class="valid">This document was successfully checked as XHTML 1.0 Transitional!</h2>
00016      #
00017     
00018     
$w3c
= "http://validator.w3.org/check?uri=$uri" ;
00019     
$resultat
= false ;
00020     
$phrase
= "" ;
00021     
00022     
$fhw3c
= @fopen($w3c,"r") ;
00023     
00024      if (
$fhw3c) {
00025     
$fini
= false ;
00026     
$txt
= "" ;
00027     
$vu1
= 0 ; # pour document invalide
00028     
$vu2
= 0 ;
00029     
$ci2
= "<h2 id=\"results\" class=\"invalid\">Errors found " ;
00030     
$vu3
= 0 ; # pour document valide
00031     
$vu4
= 0 ;
00032     
$vu5
= 0 ;
00033     
$ci4
= "<h2 class=\"valid\">This document was successfully checked" ;
00034     
00035      while ((!
feof
($fhw3c)) and (!$fini)) {
00036     
$lig
= fgets($fhw3c,8196) ;
00037     
$txt
.= $lig ;
00038      if (
strpos
($txt,"[Invalid]")>0) { $vu1 = 1 ; } ;
00039      if (
strpos
($txt,$ci2)>0) { $vu2 = 1 ; } ;
00040      if (
strpos
($txt,"[Valid]")>0) { $vu3 = 1 ; } ;
00041      if (
strpos
($txt,$ci4)>0) { $vu4 = 1 ; } ;
00042      if (
strpos
($txt,"</h2>")>0) { $vu5 = 1 ; } ;
00043      if ((
$vu1
==1) and ($vu2==1)) { $resultat = false ; $fini = true ; } ;
00044      if ((
$vu3
==1) and ($vu4==1) and ($vu5==1) ) { $resultat = true ; $fini = true ; } ;
00045      } ;
# fin tant que
00046     
fclose
($fhw3c) ;
00047     
00048     
$debphrase
= strpos($txt,"<h2") ;
00049     
$finphrase
= strpos($txt,"</h2>") ;
00050     
$phrase
= substr($txt,$debphrase,$finphrase-$debphrase+5) ;
00051     
$phrase
= preg_replace("/\n/"," ",$phrase);
00052     
$phrase
= preg_replace("/\s+/"," ",$phrase);
00053     
$phrase
= preg_replace("/This/"," &nbsp; This",$phrase);
00054     
$phrase
= preg_replace("/Errors/","&nbsp; Errors",$phrase);
00055      } ;
# fin si
00056     
00057     
return(array(
$resultat,$phrase)) ;
00058     
00059     }
# fin de fonction estW3Cvalide
00060     
00061     #############################################################################
00062     
00063     
function
analysePage($adr) {
00064     
00065     
#############################################################################
00066     
00067     
$cre
= 0 ; # code-retour étendu
00068     
$nbe
= 0 ; # nombre d'éléments
00069     
$nba
= 0 ; # nombre d'attributs
00070     
$nbc
= 0 ; # nombre de commentaires
00071     
$nbf
= 0 ; # nombre de feuilles de style
00072     
$nbj
= 0 ; # nombre de fichiers javascript
00073     
$tdr
= array() ; # tableau des résultats
00074     
$tda
= array() ; # tableau des attributs comptés et triés
00075     
$tdrp
= array() ; # tableau temporaire des résultats
00076     
00077     
$fh
= @fopen($adr,"r") ;
00078     if (!
$fh) {
00079     
h2
(" impossible d'ouvrir l'URL associée.") ;
00080     
$cre
= 1 ; # code-retour étendu
00081     
return( array(
$cre,$nbe,$nba,$nbc,$nbf,$nbj,$tdr,$tda,$tdrp) ) ;
00082     } ;
# fin si
00083     
00084     # on renvoie ce que dit le W3C à propos du fichier
00085     
00086     
$resw3c
= estW3Cvalide($adr) ;
00087     
00088     
h2
(" Validation par le W3C : ") ;
00089     
00090     
blockquote() ;
00091      if (
$resw3c
[1]=="") {
00092     
pvide() ;
00093      } else {
00094      echo
$resw3c
[1] ;
00095      } ;
# finsi
00096     
finblockquote() ;
00097     
00098     if (!
$resw3c
[0]) {
00099     
h2
(" Attention, ce document n'est pas valide selon le W3C en tant que page Web.") ;
00100     
h2
(" Les résultats qui suivent sont donc peut-&ecirc;tre incorrects.") ;
00101     } ;
# fin si
00102     
00103     # on lit tout le fichier qu'on met dans la variable txt
00104     # via file_get_contents au lieu de la lecture classique avec fopen/fgets
00105     
00106     
$txt
= file_get_contents($adr) ;
00107     
00108     
# on passe en revue la variable txt
00109     # pour bien détecter les éléments, on essaie de mettre une fin
00110     # de ligne en cas de fin de balise
00111     # on "chope" alors toutes les balises, ouvrantes comme fermantes
00112     
00113     
$ntxt
= str_replace(">",">\n",$txt) ;
00114     
$er_bof
= "/<(.*)?>/" ; # balise ouvrante/fermante
00115     
preg_match_all
($er_bof,$ntxt,$tbof) ;
00116     
00117      foreach (
$tbof
[1] as $elt) {
00118     
00119     
$tdm
= preg_split("/\s+/",$elt) ; # tableau des mots trouvés
00120     
$lpm
= $tdm[0] ;
00121     
00122     
# on garde le reste du texte trouvé
00123     
00124     
$tdm
[0] = "" ;
00125     
$rst
= join(" ",$tdm) ;
00126     
00127     
# et on cherche les attributs
00128     
00129     
$er_atr1
= "/(.*?)='.*?'/" ; # attribut modèle 1
00130     
$er_atr2
= "/(.*?)=\".*?\"/" ; # attribut modèle 1
00131     
$lattr
= "" ;
00132     
preg_match_all
($er_atr1,$rst,$tatr1) ;
00133      foreach (
$tatr1
[1] as $att1) {
00134     
$lattr
.= " $att1 " ;
00135      } ;
# fin pour attr1
00136     
preg_match_all
($er_atr2,$rst,$tatr2) ;
00137      foreach (
$tatr2
[1] as $att2) {
00138     
$lattr
.= " $att2 " ;
00139      } ;
# fin pour attr1
00140     
00141      # on peut donc construire le tableau à renvoyer
00142     
00143     
if (!isset(
$tdrp[$lpm])) { ;
00144     
$tdrp
[$lpm] = 1 ;
00145     
$tdra
[$lpm] = $lattr ;
00146      } else {
00147     
$tdrp
[$lpm] += 1 ;
00148     
$tdra
[$lpm] .= $lattr ;
00149      } ;
# fin si
00150     
00151     
} ; # fin pour elt
00152     
00153     # ensuite, on passe en revue ce qu'on a trouvé comme balises :
00154     # on ne s'intéresse qu'aux balises ouvrantes pour
00155     # analyser leur contenu en termes d'attribut
00156     
00157     
foreach (
$tdrp as $cle=>$valeur) {
00158     
00159     
$elt
= 1 ;
00160     
$pca
= substr($cle,0,1) ;
00161     
$lat
= $tdra[$cle] ;
00162     
$lat
= trim($lat) ;
00163     
$lat
= str_replace("/\s+/"," ",$lat) ;
00164     
$tal
= preg_split("/\s+/",$lat) ;
00165     
00166     
# comptage des attributs (= mots)
00167     
00168     
$cdm = array() ;
00169      foreach (
$tal
as $mot) {
00170      if (!isset(
$cdm
[$mot])) {
00171     
$cdm
[$mot] = 1 ;
00172      } else {
00173     
$cdm
[$mot]++ ;
00174      } ;
# fin pour
00175     
} ; # fin pour chaque
00176     
00177      # tri et stockage des comptages d'attribut
00178     
00179     
ksort
($cdm) ;
00180     
$ldc
= "" ;
00181      foreach (
$cdm
as $mot=>$cnt) {
00182      if (
strlen
(trim($mot))>0) {
00183     
$ldc
.= "$mot ($cnt) ; " ;
00184     
$nba
+= $cnt ;
00185      } ;
# fin de si
00186     
} ; # fin pour chaque
00187      # on remplace le dernier ; par un point
00188     
if (
strlen(trim($ldc))>0) {
00189     
$ldc
= substr($ldc,0,strlen($ldc)-3)."." ;
00190      } ;
# fin si
00191     
00192      ## on ne conserve que les éléments SGML ou les balises de début
00193     
00194      ## if ($pca=="?") { $elt = 0 ; }
00195     
if (
$pca=="/") { $elt = 0 ; }
00196      if (
$cle
=="!--") { $nbc = $valeur ; } ;
00197      if (
$cle
=="script") { $nbj = $valeur ; } ;
00198      if (
$cle
=="link") { $nbf = $valeur ; } ;
00199      if (
$elt
==1) {
00200     
$nbe
+= $valeur ;
00201     
$tdr
[$cle] = $valeur ;
00202     
$tda
[$cle] = $ldc ;
00203      } ;
# fin si
00204     
} ; # fin pour
00205     
00206      # il ne reste plus qu'à trier les éléments par ordre alphabétique
00207     
00208     
ksort
($tdr) ;
00209     
00210     return( array(
$cre
,$nbe,$nba,$nbc,$nbf,$nbj,$tdr,$tda) ) ;
00211     
00212     }
# fin de fonction analysePage($adr) {
00213     
00214     #############################################################################
00215     
00216     
function
codeHtml($url) {
00217     
00218     
#############################################################################
00219     
00220     
blockquote() ;
00221     
pre
("cadre") ;
00222     
$fh
= fopen($url,"r") ;
00223     echo
"\n" ;
00224     while (!
feof
($fh)) {
00225     
$lig
= fgets($fh, 4096) ;
00226     
$lig
= preg_replace("/\n/","",$lig);
00227     
$lig
= preg_replace("/>/",">\n",$lig);
00228     
$lng
= strlen($lig) ;
00229     
$idc
= 0 ;
00230     
$ligs
= "" ;
00231      while (
$idc
<$lng) {
00232     
$cc
= substr($lig,$idc,1) ;
00233      if (
$cc
=="<") { $cc = "&lt;" ; } ;
00234      if (
$cc
==">") { $cc = "&gt;" ; } ;
00235      if (
$cc
=="&") { $cc = "&amp;" ; } ;
00236     
$ligs
.= $cc ;
00237     
$idc++ ;
00238      } ;
# fintant que
00239     
echo
$ligs ;
00240     } ;
# fin tant que
00241     
fclose
($fh) ;
00242     
finpre() ;
00243     
finblockquote() ;
00244     
00245     }
# fin de fonction codeHtml
00246     
00247     #############################################################################
00248     
00249     
?>

Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.

 

 

retour gH    Retour à la page principale de   (gH)