I\'m looking to replace all instances of spaces in urls with %20. How would I do that with regex?
Thank you!
I think you must use rawurlencode() instead urlencode() for your purpose.
sample
$image = 'some images.jpg';
$url = 'http://example.com/'
With urlencode($str) will result
echo $url.urlencode($image); //http://example.com/some+images.jpg
its not change to %20 at all
but with rawurlencode($image) will produce
echo $url.rawurlencode(basename($image)); //http://example.com/some%20images.jpg