php - replace all matches in string after given position without regular expressions -


i have string abcxdefxghix. wish remove "x"s except first one. can find position of first "x" using strpos(), wish remove "x"s after position. str_replace() performs replacement of given string another, doesn't allow start position. substr_replace() gives start position, doesn't have search parameter. realize can done using preg_replace() seems should possible without regular expressions (or without crazy split/replace/assemble strategy).

i 'd old-fashioned way:

$index = strpos($input, $needle); if ($index !== false) {     $input = substr($input, 0, $index + 1).              str_replace($needle, $replacement, substr($input, $index + 1)); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -