SyntaxFix
Write A Post
Hire A Developer
Questions
For one matched character replace, use str_replace:
$string = str_replace(' ', '_', $string);
For all matched character replace, use preg_replace:
$string = preg_replace('/\s+/', '_', $string);