Using PHP Replace SPACES in URLS with

后端 未结 6 1903
太阳男子
太阳男子 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条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 19:17

    $result = preg_replace('/ /', '%20', 'your string here');
    

    you may also consider using

    $result = urlencode($yourstring)
    

    to escape other special characters as well

提交回复
热议问题