On Tue, 14 Aug 2001 12:23, Kurt Lieber wrote:
> I'm trying to update a number in a text file using eregi_replace.
>
> The original line is:
>
> $registrationLimit = 100;
>
> and I'd like to change it to:
>
> $registrationLimit = 300;
>
> now, 100 appears multiple times throughout the file, so I have to match
> on the whole string, not just 100.  I used the following code: (this
> may wrap in your mail client)
>
> $contents = eregi_replace("registrationLimit =
> ([0-9]+);","registrationLimit = " . $form_registrationLimit .
> ";",$contents);
>
> which works, but I'd like to find a more elegant way to do this, rather
> than rebuilding the entire string.  I tried:
>
> $contents = eregi_replace("registrationLimit =
> ([0-9]+);",\\1$form_registrationLimit,$contents);
>
> but that only produces:
>
> $100300
>
> (in other words, it combines the two values and strips out the
> "registrationLimit = " part...)  After reading the manual, I understand
> why, but I'm hoping there's some similar such method where I can
> parenthesize a substring in the string pattern and then replace only
> that substring with my replacement string.
>
> Any thoughts?
>
> --kurt

That sounds like a task for str_replace()

-- 
David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  

   Windows is the best GUI - It always sticks!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to