php replace first occurrence of string from 0th position -
i want search , replace first word in php follows:
$str="nothing inside"; replace 'nothing' 'something' search , replace without using substr
output should be: 'something inside'
use preg_replace() limit of 1:
preg_replace('/nothing/', 'something', $str, 1); replace regular expression /nothing/ whatever string want search for. since regular expressions evaluated left-to-right, match first instance.
Comments
Post a Comment