php - How to manipulate elements in an associative array? -


i've associative array titled $feeds (after executing print_r($feeds);) follows :

note: actual associative array $feeds large. understanding purpose i've put 1 element huge array.

   array    (       [0] => array       (          [feed_image] => array          (            [0] => <a href="http://52.1.47.143/photo/928/2_onclick_ok/userid_244/"  class=" js_photo_item_928  photo_holder_image" rel="928" ><img src="http://52.1.47.143/file/pic/photo/2015/04/9bd387c6442135834298d6a17b3f9555_240.jpg"  alt=""  width="180"  height="160"  class="photo_holder" /></a><br />            [1] => <a href="http://52.1.47.143/photo/927/8/userid_244/" class=" js_photo_item_928  photo_holder_image" rel="927"><img src="http://52.1.47.143/file/pic/photo/2015/04/6eb60ee0e258223ef72a9a632d0ce429_240.png"  alt="" height="84" width="150"  class="photo_holder"  userid="244" /></a>          )       )     ) 

first of want check whether key ['feed_image'] present in associative array $feeds. if it's present convert array $feeds['feed_image'] changing image path of each array element follows :

i want create new array 'src' attribute's value of each <img> tag. can observe in case too.

   array    (       [0] => array       (          [feed_image] => array          (            [0] => 2015/04/9bd387c6442135834298d6a17b3f9555%s.jpg            [1] => 2015/04/2015/04/6eb60ee0e258223ef72a9a632d0ce429%s.png          )       )     ) 

i tried following code didn't work. returns nothing.

$cnt = 0; foreach ($feeds $key => $value) {  if (is_array($feeds[$cnt]['feed_image'])) {     $feeds[$cnt]['feed_image'][$key] = (string) reset(simplexml_import_dom(domdocument::loadhtml($feeds[$cnt]['feed_image'][$key]))->xpath("//img/@src"));   } $cnt++; } 


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -