SyntaxFix
Write A Post
Hire A Developer
Questions
$result = preg_replace('/ /', '%20', 'your string here');
you may also consider using
$result = urlencode($yourstring)
to escape other special characters as well