-1

这是迄今为止我见过的最奇怪的事情,我完全糊涂了。请有人帮我解决这个问题。

    $variable=array();
    $count=0;
    // now im am going to loop through a resource that i made
    while(!feof($job))
    {
      $data=fgets($job);
      // i am search for different things below. search for name, date, employer
      // i am using regex to search btw
      // presume object in class works fine, and they do.
      if(search for eg name in $data, storing in $variable[$count].first($match))

      // the problem is at this point i will have access to 
      // $variable[$count].getFirst(returns value set by first) which was set above;  

      if(search for eg Employer in $data, storing in variable[$count].next($match))

      // i will have access here as well 
      // $variable[$count].getFirst(returns value set by first) which was set above

      if(search for 3rd search in $data, storing in variable[$count].name($match))

      // down here after the second if i am not able to see any of my variables set more than 2 if statements ago????
      // $variable[$count].getFirst(does not returns the value set by first()) which was set                                                          above

      if(search for 4th search in $data, storing in variable[$count].foo($match))
      // check if everything is set then count++;
    } 

现在,这些方法中的每一个都完全依赖于下一个但在 2 个 if 语句之后。我只是无法访问 $variable[count]->getfirst() 答案为空;

已编辑

这是实际的代码

require "functions/decodeEncodedUrl.php";
require "objects/jobObject.php";
$url=decodeEncodedUrl();
$profile=array();
$companies=0;
$url_search='http://www.jobbank.gc.ca/';
$startReading=0;
$job=fopen($url['url'], 'r')or die("JobBanks is failing to respond.<br>Please Try again Later");
while(!feof($job))
{
  set_time_limit(500);
  $profile[$companies]= new jobProfile();
  $trash=fgets($job);
  if(!$startReading)
  {
    if(preg_match('~RepeaterSearchResults_hypJobItem_[0-9]+~',$trash,$matches))
    {
      $startReading=true;
    }
  }
  if($startReading)
  {
    $data=$trash;
    if(preg_match("~href=\".*\"~",$data,$matches))
    {
      $temp=preg_replace("~href=~",'',$matches[0]);
      $temp=preg_replace("~\"~",'',$temp);
      $profile[$companies]->setLink($url_search.$temp);
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~>[A-Za-z-, ]+\(~",$data,$matches))
    {
      $temp=preg_replace("~>|\(~",'',$matches[0]);
      $profile[$companies]->setPosition(ucfirst($temp));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~# *[0-9]+~",$data,$matches))
    {
      $profile[$companies]->setOrderNum(preg_replace("~#| ~",'',$matches[0]));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~Employer:</strong>.*~",$data,$matches))
    {
      $temp=preg_replace("~Employer:</strong>&nbsp;~",'',$matches[0]);
      $temp=preg_replace("~<br.*~",'',$temp);
      $temp=ucfirst($temp);
      $profile[$companies]->setEmployer($temp);
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~[$][0-9]+.*~",$data,$matches))
    {
      $temp=preg_replace("~/.*~",'',$matches[0]);
      $profile[$companies]->setSalary(preg_replace("~[$]~","$ ",$temp));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~[$][0-9]+.*~",$data,$matches))
    {
      $temp=preg_replace('~[$A-Za-z0-9. ]*[/] ?~','',$matches[0]);
      $profile[$companies]->setRate(preg_replace('~<.*~','',$temp));
      var_dump($profile[$companies]);
      echo "<br>";
      echo "<br>";
    }
    if(preg_match("~Location:.*~",$data,$matches))
    {
      $temp=preg_replace('~.*;~','',$matches[0]);
      $temp=preg_replace('~^ |,~','',$temp); 
      $profile[$companies]->setCity(ucfirst($temp));
      //echo ucfirst($temp)."<br>";
    }
    if(preg_match("~Location[:<>/\,A-Za-z ]*~",$data,$matches))
    {
      $profile[$companies]->setProvince($matches[0]);
      //echo " ".$matches[0]."<br>\n";
      //echo $profile[$companies]->getLocation()."\n<br>";
    }
    if(preg_match("~[0-9]{4}/[0-9]{2}/[0-9]{1,2}~",$data,$matches))
    {
      echo $profile[$companies]->displayHTML();
      $profile[$companies]->setDate($matches[0]);
      if($profile[$companies]->allDataSet())
      {
        //echo "data was set"."<br>";
        $startReading=false;

        $companies++;
      }
      else
      {
        $startReading=false;
        $companies++;
        echo "Data was Not set";
      }
    }
  }
}
fclose($job);

一切正常,除了 $profile[number] 在存储变量时的第三个 if 语句之后根本不存储任何东西。

If
{
//Profile[number] info stored
}
if
{
//Profile[number] info available
}
if
{
//profile[number] info available
}
if
{
//profile[number] info is gone
}
4

1 回答 1

1

variable[$count].next($match) .next() 将内部指针移动到数组中的下一个元素。

于 2012-09-17T20:07:29.530 回答