Created
June 2, 2010 16:07
-
-
Save wesbillman/422591 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_image_from_content($content) { | |
// Define the pattern to search | |
$szSearchPattern = '~<img [^\>]*\ />~'; | |
// Run preg_match_all to grab all the images and save the results in $aPics | |
preg_match_all( $szSearchPattern, $content, $aPics ); | |
// Count the results | |
$iNumberOfPics = count($aPics[0]); | |
// Check to see if we have at least 1 image | |
if ( $iNumberOfPics > 0 ) | |
{ | |
return $aPics[0][0]; | |
}; | |
return "<img class="default" src='".bloginfo("template_directory")."'/images/default.jpg' alt='Photo Coming Soon' width='60' height='60' />"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment