-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() にアクセスできません。答えは null です。

編集済み

これが実際のコードです

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] 変数が保存されたときに3番目の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 に答える