hakkikonu hakkikonu - 6 months ago 20
PHP Question

Replace string or explode() function

I have a link in format like

http://example.com/a/b.swf


I want to to convert it to

http://cache.example.com/a/b.swf


How can I do it?

I tried it with PHP's
explode()
function, but when I explode some part of string, then I add it to itself it does not work.

Answer
$str = 'http://example.com/a/b.swf';
$str = str_replace('http://', 'http://cache.', $str);