Extract the source from an img tag with PHP

You can extract the source from an img tag with this PHP function:

function get_src_from_img($string){
     if (preg_match('/
         return $arrResult[1];  // Should display http://path.to/img
     } else {
         return "No src found";
     }
}

Comes in handy with wordpress sometimes.

Leave a comment