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
<?php
// 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
if(empty($first_img))
{
$first_img = "default.png";
}
return $first_img;
}
//...
$html = '........<img src="svnlabs.png" /> .......................';
//...
echo get_first_image_of_content($html);
?>