Reply to Re: unexpected T_DNUMBER = HUH?

Your name:

Reply:


Posted by comp.lang.php on 12/06/05 21:54

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($oldversion)).')(.*)$`i';
$contents = preg_replace($pattern, '$1 ' . $newversion . '$2',
$contents);
[/PHP]

No errors! Even this produced no errors:

[PHP]
$contents = preg_replace('/`^(\s*\*\s+\@version)\s*('.
str_replace('/','\\/',preg_quote($oldversion)).')(.*)$`/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:
> 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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация