我有一个格式的链接,如
http://example.com/a/b.swf
我想将其转换为
http://cache.example.com/a/b.swf
我该怎么做?
我尝试使用 PHP 的explode()
函数,但是当我分解字符串的某些部分时,我将它添加到自身,它不起作用。
我有一个格式的链接,如
http://example.com/a/b.swf
我想将其转换为
http://cache.example.com/a/b.swf
我该怎么做?
我尝试使用 PHP 的explode()
函数,但是当我分解字符串的某些部分时,我将它添加到自身,它不起作用。
$new_string = str_replace('http://example.com/', 'http://cache.example.com/', $orig_string);
?
$str = 'http://example.com/a/b.swf';
$str = str_replace('http://', 'http://cache.', $str);
如果你想更“专业”,那就使用一个特殊的函数http://php.net/manual/en/function.parse-url.php来解析 URL。
尝试str_replace:str_replace ($search , $replace , $subject [, int &$count ])
$str = 'http://example.com/a/b.swf';
$substr = 'http://';
$attachment = 'cache.';
$newstring = str_replace($substr, $substr.$attachment, $str);