Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2010 19:41
What would you like to do?
function get_first_image($html)
// We're trying to find and retrieve the SRC of the first image tag in the content
preg_match("/<img(.*)>/Uise", $html, $matches);
if(@trim($matches[1]) !== "")
// Found an image tag!
// Get the SRC parameter ...
preg_match("/src=\"(.*)\"/Uise", $matches[1], $image);
// ... and return it
return $image[1];
// Return the path to an "image not found", or something similar
return "...";
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment