Posted By

browncardigan on 02/08/10


Tagged


Versions (?)

getImage


Published in: PHP 


URL: http://bettesmidler.com/code/2009-07-06.htm

  1. function getImage($str) {
  2. if (strstr($str, "<img ")) {
  3. $chunks = explode("<img ", $str);
  4. foreach ($chunks as $chunk) {
  5. if (strstr($chunk, "src=")) {
  6. $img = preg_replace('|.*src=(.*?)>.*|is', '$1', strip_tags($chunk, '<img>'));
  7. $i = explode(" ", $img);
  8. $img_split = explode("/", $img);
  9. if (isset($img_split[1])) {
  10. $url = str_replace("'", "", str_replace("\"", "", $i[0]));
  11. if (!strstr($url, "/")) { unset($url); }
  12. else { break; }
  13. }
  14. }
  15. }
  16. }
  17. return isset($url) ? $url : false;
  18. }

Report this snippet 

You need to login to post a comment.