Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Oct 6th, 2008 | Syntax: PHP | Size: 1.18 KB | Hits: 525 | Expires: Never
Copy text to clipboard
  1. <pre>
  2. <?php
  3. function checktables($html){
  4.   $tables=preg_match_all('/<table /i',$html,$matches);
  5.   $withsummary=preg_match_all('/<table [^>]*\bsummary=/i',$html,$matches);
  6.   if($tables==$withsummary){
  7.     $withsummary="all";
  8.   }
  9.   echo "I found $tables tables and $withsummary of them have summary atttribute.<br>";
  10. }
  11. $file='<table border="4" summary="Hi"></table><table border="7" summary="Hi33443"></table>';
  12. checktables($file);
  13. $file='<table border="4"></table><table border="7" summary="Hi33443"></table>';
  14. checktables($file);
  15. function checkth($html){
  16.   $thcount=preg_match_all('#<th>#i',$html,$ths);
  17.   $withabbr=preg_match_all('#<th>(?:(?!</th>).)*<abbr #is',$html,$ths);
  18.   echo ($thcount==$withabbr) ? "Every th element I found had abbr attribute" : "I found th element with no abbr attibute";
  19.   echo "<br>";
  20. }
  21. $file='<table border="4"><tr><th><abbr title="et cetera">etc.</abbr></th></tr></table><table border="7" summary="Hi33443"></table>';
  22. checkth($file);
  23. $file='<table border="4"><tr><th><abbr title="et cetera">etc.</abbr></th></tr></table><table border="7" summary="Hi33443"><tr><th>etc.</th></tr><tr><th><abbr title="yes">yeap.</abbr></th></tr></table>';
  24. checkth($file);
  25. ?>