|  | Posted by comp.lang.php on 12/06/05 21:51 
Good News: The T_DNUMBER error is gone, but makes absolutely no sensewhy 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($oldversion)).')(.*)$`i';
 $contents = preg_replace($pattern, '\\1 ' . $newversion,
 $contents);
 [/PHP]
 
 So it's half fixed :)
 
 Phil
 
 Justin Koivisto wrote:
 > comp.lang.php wrote:
 > > Offensive Line:
 > > [PHP]
 > > 	    $contents =
 > > preg_replace('/([\s\t]*\*+[\s\t]*@[vV][eE][rR][sS][iI][oO][nN][\s\t]+)'
 > > . str_replace('/', '\\/', preg_quote($oldversion)) . '([\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
 > >
 >
 > 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($old_version)).')(.*)$`i';
 > $contents = preg_replace($pattern,'\\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_replace($old_version,$new_version,$content);
 >
 > May not apply in your case, but if it does, it's better.
 >
 > HTH
 >
 > --
 > Justin Koivisto, ZCE - justin@koivi.com
 > http://koivi.com
  Navigation: [Reply to this message] |