Using PHP Replace SPACES in URLS with

后端 未结 6 1902
太阳男子
太阳男子 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:23

        public static function normalizeUrl(string $url) {
            $parts = parse_url($url);
            return $parts['scheme'] .
                '://' .
                $parts['host'] .
                implode('/', array_map('rawurlencode', explode('/', $parts['path'])));
    
        }
    

提交回复
热议问题