I’m trying to remove first word from given string. I’m done so far…
$word = 'removeMe|meow|whatever';
$needle = 'removeMe';
$haystack = ''; // To replace with.
$word = str_replace( $needle, $haystack, $word );
It’s working great, but problem is when $word is something like this…
$word = 'removeMe|meow|removeMe|whatever';
I don’t want to remove second $needle. Is it possible and how? )
Unfortunately PHP doesn’t support this by default. Here’s a function doing it:
If you want to replace the text only at the beginning of the string:
If your string is actually a
|-separated list, see @lonesomeday’s answer.