Extract data from XHTML tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Markus Elfring

    Extract data from XHTML tag

    Hello,
    I try to get the contents behind the tag name.

    www@mike:/home/www > /usr/local/bin/php -a
    Interactive mode enabled

    <?php
    if (preg_match('<( ?:body|BODY)("[^"]*"|\'[^\']*\'|[^">\'])*>',
    '<body bgcolor="#fffff f">',
    $Match))
    {
    print($Match[1]);
    }
    else
    {
    print('No match!');
    }
    ?>
    X-Powered-By: PHP/4.2.3
    Content-type: text/html

    <br />
    <b>Warning</b>: Unknown modifier ''' in <b>-</b> on line <b>11</b><br
    />
    No match!


    Why does this pattern not work?
    I get more by the statements in the following programming language.

    % info tclversion
    8.3
    % if [regexp {<(?:body|BODY) ("[^"]*"|'[^']*'|[^">'])*>} {<body
    bgcolor="#fffff f">} X Match] \
    {
    puts "Match=$Mat ch"
    } \
    else \
    {
    puts {No match!}
    }
    Match="#ffffff"


    Have you got an idea?

    Best regards,
    Markus Elfring
  • R. Rajesh Jeba Anbiah

    #2
    Re: Extract data from XHTML tag

    Markus.Elfring@ web.de (Markus Elfring) wrote in message news:<40ed1d8f. 0409060729.721b 7ef3@posting.go ogle.com>...[color=blue]
    > Hello,
    > I try to get the contents behind the tag name.[/color]

    <snip>

    XHTML codes can be treated like XML and so you can use XML parser
    functions <http://in.php.net/xml>

    --
    | Just another PHP saint |
    Email: rrjanbiah-at-Y!com

    Comment

    • Markus Elfring

      #3
      Re: Extract data from XHTML tag

      > if (preg_match('<( ?:body|BODY)("[^"]*"|\'[^\']*\'|[^">\'])*>',[color=blue]
      > '<body bgcolor="#fffff f">',
      > $Match))
      > [...]
      > <b>Warning</b>: Unknown modifier ''' in <b>-</b> on line <b>11</b>[/color]

      I forgot to add the Perl pattern delimiters because I tried the
      function "eregi" before.
      But it does not support non-capturing parentheses.

      Comment

      • Markus Elfring

        #4
        Re: Extract data from XHTML tag

        > <b>Warning</b>: Unknown modifier ''' in <b>-</b> on line <b>11</b>

        Is there a chance that this error message can be more precise?



        I did not see the relation between the terms "modifier" and "delimiter" .
        How do you think about to get the message "Pattern delimiters are missing"?

        Comment

        • John Dunlop

          #5
          Re: Extract data from XHTML tag

          Markus Elfring wrote:
          [color=blue][color=green]
          > > <b>Warning</b>: Unknown modifier ''' in <b>-</b> on line <b>11</b>[/color]
          >
          > Is there a chance that this error message can be more precise?[/color]

          Yes, it can, but it probably won't.

          Your expression was

          <(?:body|BODY)( "[^"]*"|\'[^\']*\'|[^">\'])*>

          The '<' is treated as the opening delimiter and the first
          '>' as the ending delimiter. The character after the
          expression proper -- the ''', because '\'' in a single-
          quoted string means ''' -- is not a known pattern modifier.
          [color=blue]
          > http://perldoc.com/perl5.8.4/pod/perlrequick.html[/color]

          PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

          [color=blue]
          > I did not see the relation between the terms "modifier" and "delimiter" .[/color]

          Pattern modifiers affect matching. Delimiters enclose the
          expression.
          [color=blue]
          > How do you think about to get the message "Pattern delimiters are missing"?[/color]

          True, if both delimiters are actually missing. They're not
          though: '<' and '>' are the delimiters.

          --
          Jock

          Comment

          • Markus Elfring

            #6
            Re: Extract data from XHTML tag

            > XHTML codes can be treated like XML and so you can use XML parser[color=blue]
            > functions <http://in.php.net/xml>[/color]

            Another alternative:
            PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


            I prefer to build specific regular expressions for my needs instead of
            to use the other programming interfaces.
            I would use the XML/DOM APIs if I need more data and sophisticated
            processing.

            Comment

            • Markus Elfring

              #7
              Re: Extract data from XHTML tag

              > True, if both delimiters are actually missing. They're not[color=blue]
              > though: '<' and '>' are the delimiters.[/color]

              I have not found a documentation that specifies angle brackets as
              valid (default) pattern delimiters.

              Comment

              • Michael Fesser

                #8
                Re: Extract data from XHTML tag

                .oO(Markus Elfring)
                [color=blue][color=green]
                >> True, if both delimiters are actually missing. They're not
                >> though: '<' and '>' are the delimiters.[/color]
                >
                >I have not found a documentation that specifies angle brackets as
                >valid (default) pattern delimiters.
                >http://perldoc.com/perl5.8.4/pod/perlretut.html[/color]

                XCVII. Regular Expression Functions (Perl-Compatible)
                PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


                "... Since PHP 4.0.4, you can also use Perl-style (), {}, [], and <>
                matching delimiters."

                Micha

                Comment

                Working...