PHP has two main functions for performing simple search-and-replace operations. The first one is substr_replace
<?php $haystack = 'this is a test'; $newstr = substr_replace ($haystack, 'sad', 6, 5); echo "$newstr\n"; ?>