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

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -