Skip to content

Instantly share code, notes, and snippets.

Embed
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];
}
else
{
// Return the path to an "image not found", or something similar
return "...";
}
}
@EddieRingle

This comment has been minimized.

Copy link
Owner Author

@EddieRingle EddieRingle commented Apr 1, 2010

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