Skip to content

Instantly share code, notes, and snippets.

@EddieRingle
Created April 1, 2010 19:41
Show Gist options
  • Save EddieRingle/352264 to your computer and use it in GitHub Desktop.
Save EddieRingle/352264 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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