Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Help for tables

Last post 10-06-2008, 2:39 PM by ddrudik. 3 replies.
Sort Posts: Previous Next
  •  10-06-2008, 8:59 AM 46907

    Help for tables

    Hi all,

    I want to check a site if table elements exist.

    So I use :

    preg_match_all('%<table[^>]*>.*?</\1>%'$file$matches);
     
     

     I want for every  table element I found to ckeck if has summary attribute.

     

    If all the tables havesummary --> From %d tables I found all of them have summary attribute.

    Or  print --> From %d tables I found %d havingsummary attribute.

     

    And something else I want to ckeck if a table has <th> element , check between <th> and </th> if exist <abbr> attribute

     

    Thanks a lot

  •  10-06-2008, 10:28 AM 46910 in reply to 46907

    Re: Help for tables

    \1 in that content would only work if you had the tag in parens:

    preg_match_all('%<(table)\b[^>]*>.*?</\1>%'$file$matches);
     
     

    Please provide an example of your source text and what you want to match.


  •  10-06-2008, 11:31 AM 46916 in reply to 46910

    Re: Help for tables

    Case 1

    $file="<table border="4" summary="Hi"></table><table border="7" summary="Hi33443"></table>";

    print : I found 2 tables and all of them have summary attribute.

     

     Case 2

    $file="<table border="4"></table><table border="7" summary="Hi33443"></table>";

    print : I found 2 tables and 1 of them has summary attribute

     

    -----------------------------------------------------

    Cases for the other question

     

    Case 1:

    $file="<table border="4"><tr><th><abbr title="et cetera">etc.</abbr></th></tr></table><table border="7" summary="Hi33443"></table>";

    print : Every th element I found had abbr attribute

     

    Case 2:

    $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>";

    print : I found th element with no abbr attibute

  •  10-06-2008, 2:39 PM 46923 in reply to 46916

    Re: Help for tables

View as RSS news feed in XML