#!/usr/bin/php -qC // Extract_HTML_Tag.php // 2008-03-01 // Chieh Cheng // http://www.CynosureX.com/ // GNU General Public License (GPL) Version 2, June 1991 $args = count ($argv); if ($args == 3) { $file = $argv [1]; $tag = $argv [2]; if (is_file ($file)) { $content = file_get_contents ($file); $content = ereg_replace ("[\r\n]", " ", $content); $pattern = "/<" . $tag . ".*>.*<\/" . $tag . ">/i"; $result = preg_match_all ($pattern, $content, $matches); if ($result == 0) { $pattern = "/<" . $tag . "[^>]*>/i"; $result = preg_match_all ($pattern, $content, $matches); } if ($result != 0) { $entries = $matches [0]; foreach ($entries as $match) { echo $match . "\n"; } } } else { echo $file . " does not exist!\n"; } } else { $scriptName = $argv [0]; echo " Usage: " . $scriptName . " \"file\" \"tag\"\n"; } ?>