I am calling an api and replacing remote url's with my own ones.
http://example.com/a/b/icon_name.gif to http://example.org/c/d/icon_name.png. The domain name is replaced as well as the file name extension from .gif to .png. What is the more economical way to replace two parts of the string than to use two functions?
$hourlyUrl = array_map(
function($str) {
return str_replace('example.com/a/b/', 'example.org/c/d/', $str);
},
$hourlyUrl
);
$hourlyUrl = array_map(
function($str) {
return str_replace('.gif', '.png', $str);
},
$hourlyUrl
);
str_replace(array('example.com/a/b/', '.gif'), array('example.org/c/d/', '.png'), $str);