enmi12/glossaire/writeWords.php
changeset 0 d970ebf37754
child 1 f6eb5a861d2f
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1  <!DOCTYPE html>
       
     2  <html class="no-js">
       
     3  <head>
       
     4         <meta charset="iso-8859-1">
       
     5         <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1, charset=iso-8859-1">
       
     6         <title></title>
       
     7         <meta name="description" content="">
       
     8         <meta name="viewport" content="width=device-width">
       
     9 
       
    10         <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
       
    11 
       
    12         <link rel="stylesheet" href="css/normalize.css">
       
    13         <link rel="stylesheet" href="css/style.css">
       
    14         <!--<script src="js/vendor/modernizr-2.6.2.min.js"></script>-->
       
    15     </head>
       
    16     <body>
       
    17 <?php
       
    18 function removeAccents($str, $charset='utf-8')
       
    19 			{
       
    20 				$str = htmlentities($str, ENT_NOQUOTES, $charset);
       
    21 				
       
    22 				$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
       
    23 				$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. '&oelig;'
       
    24 				$str = preg_replace('#&[^;]+;#', '', $str);
       
    25 				$str = str_replace(' ','',$str);
       
    26 				
       
    27 				return $str;
       
    28 			}
       
    29 function writeLinks(){
       
    30 				$document = 'mots.xml';
       
    31 				$document_xml = new DomDocument();
       
    32 				$document_xml->load($document);
       
    33 				$elements = $document_xml->getElementsByTagName('glossaire');
       
    34 				$resultat_html = '';
       
    35 				$arbre = $elements->item(0);
       
    36 				
       
    37 				$mots = $arbre -> childNodes;
       
    38 				
       
    39 				$monfichier = fopen('mots.txt', 'r+');
       
    40 				fseek($monfichier, 0);
       
    41 				
       
    42 				$value = 0;
       
    43 				
       
    44 				foreach($mots as $mot){
       
    45 					if($mot->hasChildNodes()){
       
    46 					if($mot->hasAttributes()){
       
    47 						$wordName = $mot -> getAttribute('name');
       
    48 						$wordName = removeAccents($wordName);
       
    49 						$wordName = strtolower($wordName);
       
    50 						echo($wordName);
       
    51 					}
       
    52 					else{
       
    53 						echo($mot -> nodeValue);
       
    54 					}
       
    55 					
       
    56 					if(isset($wordName)){
       
    57 						$wordUrl = 'http://enmi12.org/glossaire/index.php?mot=' . $wordName;
       
    58 					}
       
    59 					else{
       
    60 						echo($mot -> nodeValue);
       
    61 					}
       
    62 					
       
    63 					fseek($monfichier, 0, SEEK_END);
       
    64 					
       
    65 					if(isset($wordName) && isset($wordUrl)){
       
    66 fputs($monfichier, '
       
    67 <link wordName="' . $wordName . '">
       
    68 	' . $wordUrl . '
       
    69 </link>');
       
    70 					$value++;
       
    71 					echo($value);
       
    72 					}
       
    73 					}
       
    74 					
       
    75 				}
       
    76 				
       
    77 				fclose($monfichier);
       
    78 	
       
    79 }
       
    80 
       
    81 writeLinks();
       
    82 ?>
       
    83 </body>
       
    84 </html>