|
Posted by Jochem Maas on 11/14/05 11:22
Dotan,
now _I'm_ sending _you_ multiple copies (last one didn't go to the list by mistake!)
Dotan Cohen wrote:
> 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."
php -r '
echo preg_replace("#the#","a","Then the big bear ate the little cat in the north of the woods.",1), "\n";
'
>
> 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
>
[Back to original message]
|