Hi every one i have 100 pages that consist on text(html) ......some have single jpg and some have 2 jpg ....... now i want build a checker that will differentiate these pages and separate single jpg and 2 jpg page(i will write myself a code who will move those pages) but my problem how or what logic behind to tell me this page have single jpg and another have 2 jpg. (i have good idea about reading text file,if else condition , loop) looking for wise advice, suggestion Thanks
I did not understand what the problem is. But if you have problem with file parsing, you can use http://simplehtmldom.sourceforge.net/manual.htm For example: <?php include_once 'simple_html_dom.php'; print_r(img_count('filename')); // return img tag count in file (for example) function img_count($filename) { $html = file_get_html($filename); return count($html->find('img')); // } ?> PHP:
Or use simply preg_match to find .jpg files and if count is more then do something if count is 1 or if count is 2...? If you have design related .jpg files and there are 10 of them for example, simply set script to search if there are 11 files or 12 files and then do your magic...
regex can be difficult -- but you don't need no stupid bloated library like simplehtmldom when PHP already has a perfectly good DOM parser! function imageCount($filename) { $dom = new DOMDocument(); $dom->loadHTMLFile($filename); return $dom->getElementsByTagName('img')->length; } Code (markup): Though that returns all img tags, if you want to differentiate jpeg's separate from any other img... function jpegCount($filename) { $dom = new DOMDocument(); $dom->loadHTMLFile($filename); $count=0; if ($list=$dom->getElementsByTagName('img')) { foreach ($list as $img) { $test = strtolower(substr($img->getAttribute('src'),-4)) if ( ($test == '.jpg') || ($test == 'jpeg')) $count++; } } return $count; } Code (markup): Not that hard. (assuming I didn't make any typo's since I'm on the laptop, so code untested)