Using PHP Replace SPACES in URLS with

后端 未结 6 1904
太阳男子
太阳男子 2020-11-27 18:46

I\'m looking to replace all instances of spaces in urls with %20. How would I do that with regex?

Thank you!

6条回答
  •  旧时难觅i
    2020-11-27 19:13

    No need for a regex here, if you just want to replace a piece of string by another: using str_replace() should be more than enough :

    $new = str_replace(' ', '%20', $your_string);
    


    But, if you want a bit more than that, and you probably do, if you are working with URLs, you should take a look at the urlencode() function.

提交回复
热议问题