Quote:
Originally Posted by Fou-Lu
A simple preg_match_all will fetch the classes into an array. I don't know how you want to identify the array though; we can retrieve the classes, but are you wanting to create an associative array with the element name as an index or do you need to track it at all?
I need to see example input and expected output in order to make this determination.
|
<?php
error_reporting(E_NOTICE | E_ALL);
set_time_limit(60);
global $in_string, $out_string ;
$in_string = "class=";
//$out_string = "black_heading";
$cnt = 0;
process('./');
function do_check($path)
{ global $in_string, $out_string ;
// echo "in fn do_check in is $in_string out is $out_string <br>";
if (filesize($path)>250000)
{
echo "<span style='background: blue'>FILE TOO LONG $path</span>";
return;
}
// echo $path.'<br>';
$lines = file ( $path );
// Loop through our array, show HTML source as HTML source; and line numbers too.
$content = "";
$cnt = 1;
foreach ( $lines as $line_num => $line ) {
// echo "processing $cnt $line_num $line<br/>";
if ( strpos($line, $in_string) !== false) {
$line_num = $line_num + 1;
//echo "string==>".stripslashes($in_string)."<br>\n";
//echo "count==>".$cnt."<br>";
//echo "path==>".$path."<br>";
//echo "line number==>".$line_num."<br>";
//echo htmlspecialchars($line, ENT_NOQUOTES, "UTF-8");
$linesss = str_replace(array("<", ">"), array("<", ">"), htmlspecialchars($line, ENT_NOQUOTES, "UTF-8"));
echo "<br><br><br>";
// replace with out_string
$cnt++;
}
}
}
function process($path)
{ global $in_string, $out_string ;
// echo "in fn process in is $in_string out is $out_string <br>";
//echo "<span class='cd'>-]</span> $path<br>";
$array_ext_mask_lowercase = array('html', 'htm', 'js', 'php', 'tpl');
if ($handle = opendir($path))
{
/* To jest poprawna metoda */
while (false !== ($file = readdir($handle)))
{
if ($file=='.' || $file=='..')
continue;
$npath = str_replace('//', '/', $path.'/'.$file);
if (strpos($file, '.') !== false)
{
$ext = strtolower(substr($file, strrpos($file, '.')+1));
if (in_array($ext, $array_ext_mask_lowercase))
do_check($npath);
}
if (is_dir($npath))
process($npath);
}
}
}
function readdir_arr($path, $array_ext_mask_lowercase)
{ global $in_string, $out_string ;
// echo "in fn readdir_arr in is $in_string out is $out_string <br>";
if (!is_array($array_ext_mask_lowercase))
$array_ext_mask_lowercase = array($array_ext_mask_lowercase);
$ret = array();
if ($handle = opendir($path))
{
/* To jest poprawna metoda */
while (false !== ($file = readdir($handle)))
{
if (strpos($file, '.')===false)
continue;
$ext = strtolower(substr($file, strrpos($file, '.')+1));
if (in_array($ext, $array_ext_mask_lowercase))
$ret[]= str_replace('//', '/', $path.'/'.$file);
}
}
return $ret;
}
?>