For example there is a string :
$valeur = "a-b-c-b-d-e";
The letter "b" is present twice in this. I want to replace only the first "b".
How to do that ? I used str_replace but it replaces all occurences.
For example there is a string :
$valeur = "a-b-c-b-d-e";
The letter "b" is present twice in this. I want to replace only the first "b".
How to do that ? I used str_replace but it replaces all occurences.
You cab try preg_replace here.
$valeur = "a-b-c-b-d-e";
echo preg_replace('/b/', 'x', $valeur, 1); // outputs 'a-x-c-b-d-e'
Here 4th parameter is for limit and this is optional.
thanks