我有一个格式的链接,如
http://example.com/a/b.swf我想把它转换成
http://cache.example.com/a/b.swf我该怎么做呢?
我用PHP的explode()函数尝试了它,但是当我打开字符串的某个部分时,我将它添加到它本身中,它不起作用。
发布于 2013-09-29 21:25:53
$str = 'http://example.com/a/b.swf';
$str = str_replace('http://', 'http://cache.', $str);发布于 2013-09-29 21:24:32
$new_string = str_replace('http://example.com/', 'http://cache.example.com/', $orig_string);发布于 2013-09-29 21:25:16
如果你想变得更“专业”,那么就使用一个特殊的函数http://php.net/manual/en/function.parse-url.php来解析URL。
https://stackoverflow.com/questions/19083428
复制相似问题