Manuel PHP

tidy_parse_string

(PHP 5, PECL tidy >= 0.5.2)

tidy_parse_string Analyse un document HTML contenu dans une chaîne

Description

Style procédural :

tidy tidy_parse_string ( string $input [, mixed $config [, string $encoding ]] )

Style orienté objet :

bool tidy->parseString ( string $input [, mixed $config [, string $encoding ]] )

tidy_parse_string() analyse un document contenu dans une chaîne.

Le paramètre config peut prendre la forme d'un tableau ou d'une chaîne de caractères. Sous forme de chaîne, il représente le nom du fichier de configuration et sinon, c'est un tableau avec les options de configuration. Lisez » http://tidy.sourceforge.net/docs/quickref.html pour en savoir plus sur chaque option.

Le paramètre encoding spécifie le jeu de caractères utilisé pour les documents en entrées et sorties. Les valeurs possibles de encoding sont : ascii, latin0, latin1, raw, utf8, iso2022, mac, win1252, ibm858, utf16, utf16le, utf16be, big5 et shiftjis.

Exemple #1 Exemple avec tidy_parse_string()

  1. <?php
  2. ob_start();  
  3. ?>
  4.  
  5. <html>
  6. <head>
  7. <title>test</title>
  8. </head>
  9. <body>
  10. <p>erreur<br />une autre ligne</p>
  11. </body>
  12. </html>
  13.  
  14. <?php
  15. $buffer = ob_get_clean();  
  16. $config = array('indent' => TRUE,  
  17. 'output-xhtml' => TRUE,  
  18. 'wrap', 200);  
  19.  
  20. $tidy = tidy_parse_string($buffer, $config, 'UTF8');  
  21.  
  22. $tidy->cleanRepair();  
  23.  
  24. echo $tidy;  
  25. ?> 

L'exemple ci-dessus va afficher :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> test </title> </head> <body> <p> error<br /> another line </p> </body> </html>

Note: Les paramètres optionnels config et encoding ont été ajoutés en Tidy 2.0.

Voir aussi tidy_parse_file(), tidy_repair_file() et tidy_repair_string().


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique