Replace text inside an array in PHP -
i have array in php $aresults full thousands of urls looks this:
array ( [0] => http://test.com/server1/image?img=nortel.jpg ) array ( [1] => http://test.com/server1/image?img=network.jpg )
i need replace text inside each url , replace server server1 server5 , word image photo each url should this:
http://test.com/server5/photo?img=
how accomplish this?
i have tried variation of str_replace functions cannot work:
$simgurl = $aresults[1][0]; $filter_url ='server1/image'; $replace='server5/photo'; $filtered_url = str_replace($filter_url, $replace, $aresults); print_r($aresults);
what best way accomplish this? thanks
for ($i = 0; $i <= sizeof($aresults); $i++) { $aresults[$i] = str_replace('server1/image', 'server5/photo', $aresults[$i]); }
Comments
Post a Comment