?
Solved

mysterious server error

Posted on 2003-03-12
4
Medium Priority
?
157 Views
Last Modified: 2008-07-03
Hello,
This script below is giving me a wierd error whenever I run it I get a DNS error/server not found
And I was just browsing through other files in the same direcotry and all!

**************************************************************
records.php
<?php


include "textdb_v3.inc.php";
$dbClass->setWorkingDb("sic");

$userDb = $dbClass->getAllValidRecords();
$sic_count = count($userDb);


$data = "";
if(empty($mode))
{

$mode = "";

}

if($sic > $sic_count)
{
echo "Done!";
//exit;
}




if($mode == "records")
{
$contents = "";


$handle = opendir('./data_id/$sic');  
while (false!==($file = readdir($handle)))
{  
if ($file != "." && $file != ".." && !is_dir( "./data_id/$file"))
{
$array2[] = $file;
       
} else {

}
   


}

closedir($handle);


$f_count = count($array2);
$sic_rec = $dbClass->get($sic);


$file_id = eregi_replace(".htm", "", $array2["$f_id"]);
$dbClass->setWorkingDb("ac");
$ac_rec = $dbClass->get($file_id);
$tmp = explode(" ", "$ac_rec[val]");
$st = $tmp["2"];


$fd = fopen ("./data_id/$sic/$array2[$id]", "r");
$content = fread ($fd, filesize ("./data_id/$sic/$array2[$id]"));
fclose ($fd);

preg_match('/Selected Business Listings.*/is', $content, $matches);
$content = $matches[0];
preg_match_all('/<TD[^>]*>(.*)><\/TD>/U', $content, $matches);
foreach($matches[1] as $key=>$val)
{
    $res[$key] = tags(str_replace(" ","" , $val));
}

$i = 0;
$j = 0;
$first = true;
foreach($res as $val)
{
    if (ereg("$st",$val))
    {
         $citname = $val;
      list($city, $state) = split(' + +', $val);
         $data[$i][city] = $city;
         if (!$first)
         {
              continue;
         }
         $first = false;
    }
   
    $data[$i][city] = $city;
    $data[$i][state] = $state;

   
    if ($j == 1)
    {
         $data[$i][name] = $val;
    }
    if ($j == 2)
    {
         $data[$i][address] = $val;
    }
    if ($j == 3)
    {
         $data[$i][phone] = $val;
         $i++;
         $j = 0;
    }    
    $j ++;
}





for($i=0;$i<count($data);$i++)
{
$contents .= "\"$data[$i][name]\",\"$data[$i][address]\",\"$data[$i][city]\",\"$data[$i][state]\",\"$data[$i][phone]\"\n";
}



$fp = fopen($sic_rec[val].".csv","a+");
fputs($fp, $contents);


     if($f_id == $f_count)
     {

     $f_id = 0;
     $sic = $sic+1;

     $data .= "<meta http-equiv='refresh' content='0;URL=records.php?sic=$sic&sic_count=$sic_count&f_id=$f_id&f_count=$f_count&mode=records'>";

     } else {

     $f_id = $f_id+1;

     $data .= "<meta http-equiv='refresh' content='0;URL=records.php?sic=$sic&sic_count=$sic_count&f_id=$f_id&f_count=$f_count&mode=records'>";
     }





} else {

$dbClass->setWorkingDb("sic");
$sic_rec = $dbClass->get("1");



$handle = opendir('./data_id/1');  
while (false!==($file = readdir($handle)))
{  
if ($file != "." && $file != ".." && !is_dir( "./data_id/$file"))
{
$array2[] = $file;
       
} else {

}
   


}

closedir($handle);


$f_count = count($array2);
$f_id = 0;
$fp = fopen("$sic_rec[val].csv","a+");
fputs($fp, "\"name\",\"address\",\"city\",\"state\",\"phone\"\n");
$sic = 1;

$data .= "<meta http-equiv='refresh' content='2;URL=records.php?sic=1&sic_count=$sic_count&f_id=$f_id&f_count=$f_count&mode=records'>initializing....";



}



echo $data;



?>

**************************************************************

This site is great!
0
Comment
Question by:server_room
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
VGR earned 60 total points
ID: 8123905
sorry, but when I see things like this, I stop analyzing the "code" and I switch to position "please write proper code" :D

while (false!==($file = readdir($handle)))

//should be :
while ($file = readdir($handle))

 
0
 
LVL 2

Expert Comment

by:Hatemben
ID: 8124290
don't worry for the DNS Error ... ;)))  just make your code proper as told ya VGR :))

and btw there is no tags() function in php, it's strip_tags() ;)
0
 
LVL 15

Expert Comment

by:VGR
ID: 8126105
post here the pseudo-code of what is supposed to do the above script, we'll check it, and (time permitting) rewrite it "neat and fine"
0
 
LVL 1

Author Comment

by:server_room
ID: 8133357
That's ok, it's running really great right now. But thanks anyway!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question