<?php
if (isset($_POST['query']))
{
$query = $_POST['query'];
}
$htmls_array = array(0 => 'boy.html', 'girl.html', 'man.html','new.html','womcomplect.html','wommykof.html','womplavki.html','womshorleg.html');
$htmls_name_array = array(0 => 'Детские модели - Для мальчиков', 'Детские модели - Для девочек', 'Мужские модели - Все модели','Новые модели - Новинки','Женские модели - Женские комплекты','Женские модели - Женские майки, кофты, боди','Женские модели - Женские плавки, шортики','Женские модели - Женские шорты, леггинсы');
//$file_arr = file(getcwd().'/'.'man.html');
for($id_html=0;$id_html<count($htmls_array); $id_html++){
$col = 0;
$col_array = array();
$line_num_arr = array();
$maxColInString = 4;
$maxString =1;
$error=0;
$file_arr = file(getcwd().'/'.$htmls_array[$id_html]);
foreach ($file_arr as $line_num => $line) {
$test = preg_match ("#$query#",strip_tags($file_arr[$line_num]) ,$find);
if ($test == 1){
foreach($find as $findview){
array_push($col_array, "");
}
$col = count($col_array);
if ($maxColInString<$col){
$maxString = ceil($col/$maxColInString);
}
//echo $maxString;
}
}
foreach ($file_arr as $line_num => $line) {
$test = preg_match ("#$query#",$file_arr[$line_num] ,$find);
if ($test == 1){
$error = 1;
$line_num_find = $line_num;
array_push($line_num_arr , $line_num_find);
}
}
//$file_arr = preg_replace("#[\s]#",'',$file_arr);
if (is_numeric($query)) {
if (strlen($query)>=2) {
echo "Поиск по артикулу <em>" .$query. '</em>, в каталоге <em>' .$htmls_name_array[$id_html] .'</em>
';
echo "<table>";
for ($row = 0; $row <$maxString; $row++) {
echo "<tr>";
for($i=0;$i<$col;$i++){
//echo $col.'
';
//echo $line_num_arr[$i].'
';
if($i==4){$col = $col - 5;$i=$i+5;}
$id = array_pop($line_num_arr);
if (isset($file_arr[$id])){
$ok = preg_match ('#Арт: (\d+)#',$file_arr[$id] ,$find_art);}
if ($ok == 1){
preg_match ('#<p>(.*?)<\/p>#',$file_arr[$id+2],$find_name);
preg_match ('#\<a href\=\"(.*?[.jpg|.png|.gif])"#',$file_arr[$id+4] ,$find_img);
preg_match ('#\<img src\=\"(.*?[.jpg|.png|.gif])"#',$file_arr[$id+6] ,$find_img_mini);
}
echo "<td>";
if (isset($find_name[1])){//echo "
".$find_name[1] ."
";
//echo "Фото: <a href ='".$find_img[1]."'>...".$find[0]."...</a>" ."
";
if (isset($find_img[1])&& isset($find_img_mini[1])){echo "<a href ='".$find_img[1]."' class='nivoZoom center'><img src='".$find_img_mini[1]."' width='133' height='180' class='img_search'><div class='nivoCaption'>".$find_name[1].". Арт: (".$find_art[1].")</div></a>" ."
";}
if (isset($find_art[1])){echo "<center>Арт: ".$find_art[1] ."</center>
";}
echo "</td>";
}
}
echo "</tr>";
}
}
echo "</table>";
if ($error == 0){
echo '<b> - Ничего не найдено</b>' .'
';
}
} else {
if (strlen($query)>=3) {
echo "Поиск по названию: <em>" .$query. '</em>, в каталоге <em>' .$htmls_name_array[$id_html] .'</em>
';
echo "<table>";
for ($row = 0; $row < $maxString; $row++) {
echo "<tr>";
for($i=0;$i<$col;$i++){
//echo $line_num_arr[$i].'
';
if($i==4){$col = $col - 5;$i=$i+5;}
$id = array_pop($line_num_arr);
if (isset($file_arr[$id])) {
$ok = preg_match ('#<p>(.*?)<\/p>#',$file_arr[$id],$find_name);}
if ($ok == 1){
if (isset($file_arr[$id])) {preg_match ('#(?s)Арт: (\d+)#',$file_arr[$id-2] ,$find_art);
preg_match ('#\<a href\=\"(.*?[.jpg|.png|.gif])"#',$file_arr[$id+2] ,$find_img);
preg_match ('#\<img src\=\"(.*?[.jpg|.png|.gif])"#',$file_arr[$id+4] ,$find_img_mini);
}
echo "<td>";
if (isset($find_name[1])){//echo "
".$find_name[1] ."
";
//echo "Фото: <a href ='".$find_img[1]."'>...".$find[0]."...</a>" ."
";
if (isset($find_img[1])&& isset($find_img_mini[1])){echo "<a href ='".$find_img[1]."' class='nivoZoom center'><img src='".$find_img_mini[1]."' width='133' height='180' class='img_search'><div class='nivoCaption'>".$find_name[1].". Арт: (".$find_art[1].")</div></a>" ."
";}
if (isset($find_art[1])){echo "<center>Арт: ".$find_art[1] ."</center>
";}
echo "</td>";
}
}
}
echo "</tr>";
}
echo "</table>";
if ($error == 0){
echo '<b> - Ничего не найдено</b>' .'
';
}
}
}
}
?>