If you need to check if a string is found in another string, you might like this.
<?php if(strpos('_name_', $str) === false) { //String '_name_' is not found //Do nothing, or you could change this to do something } else { //String '_name_' found //Replacing it with string '_title_' $str = str_replace('_name_','_title_',$str); } ?>
http://php.net/manual/en/function.strpos.php
However, for this example you do not need. If you run str_replace on a line that does not replace anything, it will not find anything to replace and will simply move without any replacements or changes.
Good luck.
source share