FAQ: replace first instance (couldn't find in archive)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've seen this discussed before, but no solution seems to have ever
been suggested. I'd like to replace the first instance of a substring
in a string. So if we were to replace the first 'the' with 'a' in the
sentance
"Then the big bear ate the little cat in the north of the woods."
we would have:
"Then a big bear ate the little cat in the north of the woods."

I'm on PHP Version 4.3.11, but I can't seem to do anything useful with
the preg_replace() limit parameter, which is supposed to be on
php>=4.0.1

Does anybody have an example of working code that does this? I've
never asked for code before, but this time I think that I already DO
know what functions I need, I just can't seem to make it connect....

Side note, in google I couldn't find anything for php that would do
what I want, but I found several perl archives that have a solution.
If need be, I can paste that perl code. Maybe someone will be able to
translate it into php. Thanks!

Dotan
http://lyricslist.com/lyrics/artist_albums/274/jamiroquai.php 
Jamiroquai Song Lyrics

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux