Get First Image of Content

Hits: 2644  

Steps I follow …..

a) Audit the whole script. -> Concentrate
b) Divide the script into sections. -> Observe
c) Find the bug in the code. -> Imagine
d) Fix the bug or rewrite. -> Launch


// get first image of content

function get_first_image_of_content($content) {


$first_img '';

  $output preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i'$content$matches);

$first_img $matches[1][0];

  // default image if first image is blank



$first_img "default.png";






$html '........<img src="svnlabs.png" /> .......................';


echo get_first_image_of_content($html);


Kool Tap Accessories - KoolTap

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

One thought on “Get First Image of Content”

Leave a Reply

Your email address will not be published.