unexpected T_DNUMBER = HUH?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    unexpected T_DNUMBER = HUH?

    Offensive Line:
    [PHP]
    $contents =
    preg_replace('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
    .. str_replace('/', '\\/', preg_quote($old version)) . '([\n\r\s\t]*)/e',
    '$1' . $newversion . '$2', $contents);
    [/PHP]

    Bluntly put, I simply don't get it. It's bad enough that the RegExp
    fails, but why would it break and why break in such a way that makes no
    sense to anyone?

    This is all I want to do:

    REPLACE

    * @version 1.0.0

    WITH

    * @version 1.1.0

    Inside each non-binary file that contains that exact line pattern!

    And that's all.

    Thanx
    Phil

  • ZeldorBlat

    #2
    Re: unexpected T_DNUMBER = HUH?

    >Offensive Line:[color=blue]
    >[PHP]
    > $contents =
    >preg_replace ('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
    >. str_replace('/', '\\/', preg_quote($old version)) . '([\n\r\s\t]*)/e',
    >'$1' . $newversion . '$2', $contents);
    >[/PHP][/color]

    Probably not the offending line...that didn't give me any syntax
    errors. Perhaps the line before?

    Comment

    • comp.lang.php

      #3
      Re: unexpected T_DNUMBER = HUH?

      I wish that were the case. The offensive line number points to that
      exact line; the line before it is a single-line PHP comment.

      Env: PHP 4.1.2, 4.3.2, 5.0.4

      Phil

      ZeldorBlat wrote:[color=blue][color=green]
      > >Offensive Line:
      > >[PHP]
      > > $contents =
      > >preg_replace ('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
      > >. str_replace('/', '\\/', preg_quote($old version)) . '([\n\r\s\t]*)/e',
      > >'$1' . $newversion . '$2', $contents);
      > >[/PHP][/color]
      >
      > Probably not the offending line...that didn't give me any syntax
      > errors. Perhaps the line before?[/color]

      Comment

      • Justin Koivisto

        #4
        Re: unexpected T_DNUMBER = HUH?

        comp.lang.php wrote:[color=blue]
        > Offensive Line:
        > [PHP]
        > $contents =
        > preg_replace('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
        > . str_replace('/', '\\/', preg_quote($old version)) . '([\n\r\s\t]*)/e',
        > '$1' . $newversion . '$2', $contents);
        > [/PHP]
        >
        > Bluntly put, I simply don't get it. It's bad enough that the RegExp
        > fails, but why would it break and why break in such a way that makes no
        > sense to anyone?
        >
        > This is all I want to do:
        >
        > REPLACE
        >
        > * @version 1.0.0
        >
        > WITH
        >
        > * @version 1.1.0
        >
        > Inside each non-binary file that contains that exact line pattern!
        >
        > And that's all.
        >
        > Thanx
        > Phil
        >[/color]

        It's the e modifier... because $2 is not a valid variable name in PHP.
        Try something a bit simpler:

        <?php
        $pattern='`^(\s *\*\s+\@version )\s*('.
        str_replace('/','\\/',preg_quote($o ld_version)).') (.*)$`i';
        $contents = preg_replace($p attern,'\\1 '.$new_version, $contents);
        ?>

        That will replace a version number like "1.0.0/rev4" into the new one,
        assuming that the line is similar to:

        * @version 1.0.0/rev4 - some other note

        Of course, whenever you can use a string function over regex, do it:
        $content=str_re place($old_vers ion,$new_versio n,$content);

        May not apply in your case, but if it does, it's better.

        HTH

        --
        Justin Koivisto, ZCE - justin@koivi.co m

        Comment

        • comp.lang.php

          #5
          Re: unexpected T_DNUMBER = HUH?

          Good News: The T_DNUMBER error is gone, but makes absolutely no sense
          why it's gone, you CAN use '$1' - '$9' in regular expressions!

          Bad News: The pattern match failed to find the pattern to make the
          substitution using your code:

          [PHP]
          $pattern='`^(\s *\*\s+\@version )\s*('.
          str_replace('/','\\/',preg_quote($o ldversion)).')( .*)$`i';
          $contents = preg_replace($p attern, '\\1 ' . $newversion,
          $contents);
          [/PHP]

          So it's half fixed :)

          Phil

          Justin Koivisto wrote:[color=blue]
          > comp.lang.php wrote:[color=green]
          > > Offensive Line:
          > > [PHP]
          > > $contents =
          > > preg_replace('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
          > > . str_replace('/', '\\/', preg_quote($old version)) . '([\n\r\s\t]*)/e',
          > > '$1' . $newversion . '$2', $contents);
          > > [/PHP]
          > >
          > > Bluntly put, I simply don't get it. It's bad enough that the RegExp
          > > fails, but why would it break and why break in such a way that makes no
          > > sense to anyone?
          > >
          > > This is all I want to do:
          > >
          > > REPLACE
          > >
          > > * @version 1.0.0
          > >
          > > WITH
          > >
          > > * @version 1.1.0
          > >
          > > Inside each non-binary file that contains that exact line pattern!
          > >
          > > And that's all.
          > >
          > > Thanx
          > > Phil
          > >[/color]
          >
          > It's the e modifier... because $2 is not a valid variable name in PHP.
          > Try something a bit simpler:
          >
          > <?php
          > $pattern='`^(\s *\*\s+\@version )\s*('.
          > str_replace('/','\\/',preg_quote($o ld_version)).') (.*)$`i';
          > $contents = preg_replace($p attern,'\\1 '.$new_version, $contents);
          > ?>
          >
          > That will replace a version number like "1.0.0/rev4" into the new one,
          > assuming that the line is similar to:
          >
          > * @version 1.0.0/rev4 - some other note
          >
          > Of course, whenever you can use a string function over regex, do it:
          > $content=str_re place($old_vers ion,$new_versio n,$content);
          >
          > May not apply in your case, but if it does, it's better.
          >
          > HTH
          >
          > --
          > Justin Koivisto, ZCE - justin@koivi.co m
          > http://koivi.com[/color]

          Comment

          • comp.lang.php

            #6
            Re: unexpected T_DNUMBER = HUH?

            Oh, one more thing: I replaced '\\1 ' with '$1' to prove that that
            could not have been the cause of the T_DNUMBER error:

            [PHP]
            // FIND THE PATTERN OF THE OLD VERSION
            $pattern='`^(\s *\*\s+\@version )\s*('.
            str_replace('/','\\/',preg_quote($o ldversion)).')( .*)$`i';
            $contents = preg_replace($p attern, '$1 ' . $newversion . '$2',
            $contents);
            [/PHP]

            No errors! Even this produced no errors:

            [PHP]
            $contents = preg_replace('/`^(\s*\*\s+\@ve rsion)\s*('.
            str_replace('/','\\/',preg_quote($o ldversion)).')( .*)$`/i', '$1 ' .
            $newversion . '$2', $contents);
            [/PHP]

            Like I said, it's half fixed though with your variation of the regular
            expression pattern, but now simply failing to match the pattern, but no
            errors!

            Phil

            Justin Koivisto wrote:[color=blue]
            > comp.lang.php wrote:[color=green]
            > > Offensive Line:
            > > [PHP]
            > > $contents =
            > > preg_replace('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
            > > . str_replace('/', '\\/', preg_quote($old version)) . '([\n\r\s\t]*)/e',
            > > '$1' . $newversion . '$2', $contents);
            > > [/PHP]
            > >
            > > Bluntly put, I simply don't get it. It's bad enough that the RegExp
            > > fails, but why would it break and why break in such a way that makes no
            > > sense to anyone?
            > >
            > > This is all I want to do:
            > >
            > > REPLACE
            > >
            > > * @version 1.0.0
            > >
            > > WITH
            > >
            > > * @version 1.1.0
            > >
            > > Inside each non-binary file that contains that exact line pattern!
            > >
            > > And that's all.
            > >
            > > Thanx
            > > Phil
            > >[/color]
            >
            > It's the e modifier... because $2 is not a valid variable name in PHP.
            > Try something a bit simpler:
            >
            > <?php
            > $pattern='`^(\s *\*\s+\@version )\s*('.
            > str_replace('/','\\/',preg_quote($o ld_version)).') (.*)$`i';
            > $contents = preg_replace($p attern,'\\1 '.$new_version, $contents);
            > ?>
            >
            > That will replace a version number like "1.0.0/rev4" into the new one,
            > assuming that the line is similar to:
            >
            > * @version 1.0.0/rev4 - some other note
            >
            > Of course, whenever you can use a string function over regex, do it:
            > $content=str_re place($old_vers ion,$new_versio n,$content);
            >
            > May not apply in your case, but if it does, it's better.
            >
            > HTH
            >
            > --
            > Justin Koivisto, ZCE - justin@koivi.co m
            > http://koivi.com[/color]

            Comment

            • Colin Fine

              #7
              Re: unexpected T_DNUMBER = HUH?

              comp.lang.php wrote:[color=blue]
              > Oh, one more thing: I replaced '\\1 ' with '$1' to prove that that
              > could not have been the cause of the T_DNUMBER error:
              >
              > [PHP]
              > // FIND THE PATTERN OF THE OLD VERSION
              > $pattern='`^(\s *\*\s+\@version )\s*('.
              > str_replace('/','\\/',preg_quote($o ldversion)).')( .*)$`i';
              > $contents = preg_replace($p attern, '$1 ' . $newversion . '$2',
              > $contents);
              > [/PHP]
              >
              > No errors! Even this produced no errors:
              >[/color]
              Justin told you the answer to that: the /e qualifier (that you're no
              longer using). That qualifier means 'treat the pattern as a PHP
              expression, and evaluate it'.

              Colin

              Comment

              Working...