Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
creating conditional statements using curl and simplehtmldom

Im building a simple web scraper that goes to some urls and get some information, but case in the page containains specific text content, i wish to get out the current loop and continue to the next, the only strange beaviour is that i can output the label that i use to create the conditional, but it doesnt work, is like that doesnt exist.

My code:

for($i = 0; $i< 5; $i++){
curl_setopt($ch, CURLOPT_URL, 'url/details.php?med_id='.$i);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
//echo $answer;
if (curl_error($ch)) {
    echo curl_error($ch);
}

$html = str_get_html($answer);

    $table = $html->find('table', 3);
      
    /*
*$table->find('td',17)->plaintext => could be "Comercializado" or "Não comercializado", so if is  "Não comercializado" it goes to the next iteration.
I already output the text "$table->find('td',17)->plaintext" to see if appeaars and looks ok.
*/
    if (strpos($table->find('td',17)->plaintext, 'Não comercializado') !== false) {
        continue;
    }

   
    echo "<tr>";
    echo "<td>".$table->find('td',17)."</td>";
    echo "<td>".$table->find('td',14)."</td>";
    echo " <td>".$table->find('td',22)."</td>";
     echo "<td>".$table->find('td',25)."</td>";
    echo "</tr>";

}

 echo "</table>";
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!