str_replace is a very simple PHP function. It replaces chosen characters in a string.
$a = "this is a sentence"; $b = str_replace(" ", '_', $a); echo $b;
The above code will replace all the spaces in the sentence with underscores.