且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PHP将URL中的SPACES替换为%20

更新时间:2022-02-02 23:03:00

如果您只想用另一个字符串替换这里,则不需要正则表达式:使用

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);


但是,如果您想要的更多,而且您可能会这样做,并且您正在使用URL,那么应该看看


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.