preg_match and html question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam Waller

    preg_match and html question


    I need a regular expression for preg_match to find all of the strings between
    '>' and '<' from html. Eg.

    1. <TD><FONT SIZE='2'>XXX</FONT></TD>
    2. <TD><FONT SIZE='2'><A HREF=http://www.whatever.co m/...7>ZZZ</A></FONT></TD>
    3. <TD ALIGN=CENTER><F ONT SIZE='2'>Y/Y</FONT></TD>

    #1 matches should be "", "XXX", and ""
    #2 should be "", "", "ZZZ", "", ""
    #3 should be "", "Y/Y", ""

    Actually I need only the non-empty strings, but I can just ignore the empty ones.

    I've tried preg_match("/>(.*)</i", $str, $matches) but it doesn't work like I want.
    Does anyone know how to get this to work?

    thanks,
    Sam

  • Floortje

    #2
    Re: preg_match and html question

    Sam Waller wrote:
    I need a regular expression for preg_match to find all of the strings between
    '>' and '<' from html. Eg.
    >
    1. <TD><FONT SIZE='2'>XXX</FONT></TD>
    2. <TD><FONT SIZE='2'><A HREF=http://www.whatever.co m/...7>ZZZ</A></FONT></TD>
    3. <TD ALIGN=CENTER><F ONT SIZE='2'>Y/Y</FONT></TD>
    >
    #1 matches should be "", "XXX", and ""
    #2 should be "", "", "ZZZ", "", ""
    #3 should be "", "Y/Y", ""
    >
    Actually I need only the non-empty strings, but I can just ignore the empty ones.
    >
    I've tried preg_match("/>(.*)</i", $str, $matches) but it doesn't work like I want.
    Does anyone know how to get this to work?
    >
    thanks,
    Sam

    strip_tags() :-)

    --
    Arjen

    Comment

    • gosha bine

      #3
      Re: preg_match and html question

      On 10.06.2007 17:23 Sam Waller wrote:
      I need a regular expression for preg_match to find all of the strings between
      '>' and '<' from html. Eg.
      >
      1. <TD><FONT SIZE='2'>XXX</FONT></TD>
      2. <TD><FONT SIZE='2'><A HREF=http://www.whatever.co m/...7>ZZZ</A></FONT></TD>
      3. <TD ALIGN=CENTER><F ONT SIZE='2'>Y/Y</FONT></TD>
      >
      #1 matches should be "", "XXX", and ""
      #2 should be "", "", "ZZZ", "", ""
      #3 should be "", "Y/Y", ""
      >
      Actually I need only the non-empty strings, but I can just ignore the empty ones.
      >
      I've tried preg_match("/>(.*)</i", $str, $matches) but it doesn't work like I want.
      Does anyone know how to get this to work?
      >
      thanks,
      Sam
      >
      Try using a character class instead of dot: />([^<>]*)</

      --
      gosha bine

      extended php parser ~ http://code.google.com/p/pihipi
      blok ~ http://www.tagarga.com/blok

      Comment

      • Toby A Inkster

        #4
        Re: preg_match and html question

        gosha bine wrote:
        Try using a character class instead of dot: />([^<>]*)</
        Also, using + instead of * might work better for your purposes.

        --
        Toby A Inkster BSc (Hons) ARCS
        [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
        [OS: Linux 2.6.12-12mdksmp, up 107 days, 22:28.]

        URLs in demiblog

        Comment

        Working...