Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

jeff_

By: a guest on Jun 19th, 2009  |  syntax: PHP  |  size: 0.80 KB  |  hits: 179  |  expires: Never
download  |  raw  |  embed  |  report abuse
This paste has a previous version, view the difference. Copied
  1. <?
  2. $page = file_get_contents('./source/fichier.html');
  3. // ici nettoyage du code pour ne garder que ce qui est entre les balises "body"
  4.  
  5. preg_match_all('#<h([2])[^>]{0,}>(.*)</h\1>#i',$page,$match);
  6. $match = $match[0];
  7. $summary = array();
  8. foreach ($match as $m) {
  9.     $page = str_replace($m,'<!-- cut here -->'.$m,$page); // on place un marqueur de découpe
  10.     $summary[] = strip_tags($m); // on stocke les titres pour créer une page index
  11. }
  12. print_r($page);
  13. $page = explode('<!-- cut here -->',$page);
  14.  
  15. foreach ($page as $num=>$chunk) {
  16.     file_put_contents('./result/'.$num.'.html',$chunk);
  17. }
  18. $index = '';
  19. foreach ($summary as $num=>$entry) {
  20.         $index .= '<li><a href="'.$num.'.html">'.$entry.'</a></li>';
  21. }
  22. $index = '<ul>'.$index.'</ul>';
  23.  
  24. file_put_contents('./result/index.html',$index);
  25. ?>