On 23 Apr 2001 13:04:36 -0700 impersonator of
[EMAIL PROTECTED] ("Erica Douglass") planted &I saw in
php.general:

>I want to only replace the first occurrence of a string in a file using
>ereg_replace. Should I use a loop to do this? Any suggestions? Please email
>me at [EMAIL PROTECTED] with suggestions.
>
>Thanks,
>Erica
>
I think, begining from some php >4, preg_replace allows to do this,
Otherwise, you could use preg_match to find first match then strpos() to
find it position, and, finaly substr() with concatenation to your
replacement. This loong way was the first, that came to my mind for cases,
where regexp realy needed. (If they are not needed, str_replace() would
work faster/simlier, you know o'cos:). 

Note: for some strings I experience hangup, especially  w/ereg_replace,
but also, for long ones, w/preg0. Regards. Leonid.

-- 
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