commenting ?>

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

    #1

    commenting ?>

    I cant think in any reason why this code fails...

    Commented line shuldn't be completely ignored by the parser?

    <?php

    // ?whatever

    ehco 'bla bla';

    ?>


    In the real case, I'm having problems commenting out regex expressions
    such as

    $res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);

    While this doesn't work:
    // $res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);

    The following seems to be treated as expected

    /*
    $res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);
    */

    Again, I can't see the reason of that parser's behavior...

    regards- julian

  • Alvaro G. Vicario

    #2
    Re: commenting ?&gt;

    *** julian_m escribió/wrote (7 Jul 2006 11:35:08 -0700):
    I cant think in any reason why this code fails...
    >
    Commented line shuldn't be completely ignored by the parser?
    >
    <?php
    >
    // ?whatever
    According to manual:

    The "one-line" comment styles only comment to the end of the line or the
    current block of PHP code, whichever comes first. This means that HTML code
    after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
    returns to HTML mode, and // or # cannot influence that.

    It sounds like the logical option to me.



    --
    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    ++ Mi sitio sobre programación web: http://bits.demogracia.com
    +- Mi web de humor con rayos UVA: http://www.demogracia.com
    --

    Comment

    • julian_m

      #3
      Re: commenting ?&gt;

      Alvaro G. Vicario wrote:
      *** julian_m escribió/wrote (7 Jul 2006 11:35:08 -0700):
      I cant think in any reason why this code fails...

      Commented line shuldn't be completely ignored by the parser?

      <?php

      // ?whatever
      >
      According to manual:
      >
      The "one-line" comment styles only comment to the end of the line or the
      current block of PHP code, whichever comes first. This means that HTML code
      after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
      returns to HTML mode, and // or # cannot influence that.
      >
      It sounds like the logical option to me.
      >
      I didn't know that, now I understand how it works, although IMO, the
      line I commented was not de end of the current block of PHP:

      //$res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);

      Note that ?is a string there.

      regards - julian

      Comment

      • Andy Hassall

        #4
        Re: commenting ?&gt;

        On 7 Jul 2006 13:02:11 -0700, "julian_m" <julianmaisano@ gmail.comwrote:
        >Alvaro G. Vicario wrote:
        >
        >According to manual:
        >>
        >The "one-line" comment styles only comment to the end of the line or the
        >current block of PHP code, whichever comes first. This means that HTML code
        >after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
        >returns to HTML mode, and // or # cannot influence that.
        >>
        >It sounds like the logical option to me.
        >
        >I didn't know that, now I understand how it works, although IMO, the
        >line I commented was not de end of the current block of PHP:
        >
        >//$res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);
        >
        >Note that ?is a string there.
        Ah, but it isn't in a string, because it's in a comment.

        (Sounds circular, but actually it's not).

        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        • julian_m

          #5
          Re: commenting ?&gt;


          Andy Hassall wrote:
          On 7 Jul 2006 13:02:11 -0700, "julian_m" <julianmaisano@ gmail.comwrote:
          >
          Alvaro G. Vicario wrote:
          According to manual:
          >
          The "one-line" comment styles only comment to the end of the line or the
          current block of PHP code, whichever comes first. This means that HTML code
          after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
          returns to HTML mode, and // or # cannot influence that.
          >
          It sounds like the logical option to me.
          I didn't know that, now I understand how it works, although IMO, the
          line I commented was not de end of the current block of PHP:

          //$res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);

          Note that ?is a string there.
          >
          Ah, but it isn't in a string, because it's in a comment.
          >
          (Sounds circular, but actually it's not).
          Right.
          Even though someone could think "hey dude, just comment with /* */ and
          go ahead". there are situations, dealing with regex, where it wouldn't
          work. For instance:

          /*
          preg_replace('# (<\s*span\s*>\s *<\s*/\s*span\s*>|<\? xml\s*:\s*names pace.*?>|<\s*/?\s*o\s*:\s*p\s *>)#si','',... )
          */

          It's really annoying isn't it?

          regards - julian

          Comment

          • Andy Hassall

            #6
            Re: commenting ?&gt;

            On 7 Jul 2006 13:26:45 -0700, "julian_m" <julianmaisano@ gmail.comwrote:
            >For instance:
            >
            >/*
            >preg_replace(' #(<\s*span\s*>\ s*<\s*/\s*span\s*>|<\? xml\s*:\s*names pace.*?>|<\s*/?\s*o\s*:\s*p\s *>)#si','',... )
            >*/
            >
            >It's really annoying isn't it?
            Yep, nasty.

            --
            Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
            http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

            Comment

            • Malcolm Dew-Jones

              #7
              Re: commenting ?&gt;

              julian_m (julianmaisano@ gmail.com) wrote:

              : Andy Hassall wrote:
              : On 7 Jul 2006 13:02:11 -0700, "julian_m" <julianmaisano@ gmail.comwrote:
              : >
              : Alvaro G. Vicario wrote:
              :
              : According to manual:
              : >
              : The "one-line" comment styles only comment to the end of the line or the
              : current block of PHP code, whichever comes first. This means that HTML code
              : after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
              : returns to HTML mode, and // or # cannot influence that.
              : >
              : It sounds like the logical option to me.
              :
              : I didn't know that, now I understand how it works, although IMO, the
              : line I commented was not de end of the current block of PHP:
              :
              : //$res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?>#s i', '<\1>',$str);

              One solution is to split the string into pieces to break up the characters
              and then concat the pieces.


              $res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?' . '>#si', '<\1>',$str);
              ^^^^^^



              Or you can try to escape one or more of the characters to change the
              string without changing its value. I'm not sure off hand if the php escape
              works this way. What you want is to escape the character, which for
              many characters is simply gives you the character itself (in some
              languages, maybe in php).


              $res= preg_replace('# <\s*(p|span|li| ul|ol)\s+.*?\># si', '<\1>',$str);
              ^

              Comment

              Working...