<?php $string = "hello php"; $replace = str_replace(" ", "_", $string); echo $replace; // hello_php ?>