Advertisement
oim_trust

parser.php_dom2

Oct 27th, 2016
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5.  
  6.     /** Membuat dom baru**/
  7.     $dom    = new domDocument;
  8.     $dom->preserveWhiteSpace = false;  
  9.  
  10.     // memuat file data.html
  11.     $dom    -> loadHTMLFile("data.html");
  12.  
  13.     // mengambil id dari tabel
  14.     $elm = $dom->getElementById('tabel2');
  15.  
  16.     echo "</br>";
  17.     foreach ($elm->getElementsByTagName('tr') as $data) {
  18.         $d = ($dom->saveHTML($data));
  19.         $d = rip_tags($d);
  20.         $txt = explode(' ', $d);
  21.         echo "Designation : ".$txt[0].'<br/>Manager:'.$txt[1]." <br/>Team:".$txt[2];
  22.         echo "<hr/>";
  23.     }
  24.  
  25.  
  26. function rip_tags($string) {
  27.    
  28.     // ----- menghapus tag html -----
  29.     $string = preg_replace ('/<[^>]*>/', ' ', $string);
  30.    
  31.     // ----- menghapus control characters -----
  32.     $string = str_replace("\r", '', $string);    // --- replace with empty space
  33.     $string = str_replace("\n", ' ', $string);   // --- replace with space
  34.     $string = str_replace("\t", ' ', $string);   // --- replace with space
  35.    
  36.     // ----- menghapus multiple spaces -----
  37.     $string = trim(preg_replace('/ {2,}/', ' ', $string));
  38.    
  39.     return $string;
  40.  
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement