|
Posted by Justin Koivisto on 12/06/05 21:43
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
[Back to original message]
|