Welcome Guest, Not a member yet? Register   Sign In
How to get first image from blog posts
#3

If you're only trying to get the FIRST image, why use preg_match_all() which will get ALL images? Try using just preg_match() and then testing if $matches[1] exists before trying to use it. Additionally preg_match() will be slightly faster since it will stop trying to match after it finds the first entry if one exists:

$first_img = isset($matches[1]) ? $matches[1] : ''; //$first_img will be image, or empty string if it didn't exist.
Reply


Messages In This Thread
RE: How to get first image from blog posts - by CroNiX - 07-03-2015, 09:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB