<?php/* this scripts collects urls from hrefs in a sourcefile, strips out the image file names from these urls, prepends the baseUrl and outputs it to a file*/// SOURCE FILE$file = 'some_page.html';// OUPUTFILE$outputfile = 'output.urls';// url that should be prepended to all images found$baseUrl = 'http://....';// any string that if it is found in filename should be excluded$excludes = array('th_', 'exclude_me_please_because_I_am_not_real');// any string that might be _before_ (not in the beginning of) the filename$delimiters = array('=', '/');// any string that might end the filename$extensions = array('jpg', 'gif', 'png');// program starts$data = file_get_contents($file);$matches = array();$pattern = '/href="([^"]*)"/i';preg_match_all($pattern, $data, $matches);if ( ($fp = fopen($outputfile, 'w')) == false ) { die('Could not open outputfile ' . $outputfile);}foreach ( $matches[1] as $url ) { if ( $temp != $url ) { $delims = ''; foreach ( $delimiters as $delim ) { if ( $delim == '/' ) { $delim = '\\/'; } $delims .= $delim . '|'; } $delims = substr($delims, 0, -1); $exts = ''; foreach ( $extensions as $ext ) { $exts .= $ext . '|'; } $exts = substr($exts, 0, -1); $pattern = '/.*(?:'.$delims.')(.*?\.jpg|gif|png)/i'; $fileNameMatches = array(); $found = preg_match($pattern, $url, $fileNameMatches); $fileName = $fileNameMatches[1]; if ( !empty($fileName) ) { $include = true; foreach ( $excludes as $exclude ) { if ( strstr($fileName, $exclude) != false ) { $include = false; break; } } if ( $include ) { fputs($fp, $baseUrl.$fileName.chr(10)); } } } $temp = $url;}?>