string replace space with dash code example Example: php replace spaces with dash str_replace(' ', '-', $string);