I am using curl for web page scraping and I can display a result of interest.
Normally the script below outputs me the WEB SCRAPER TESTING GROUND text which is scraped and regex'ed by "title" id from the page.
Now I would like to check if the word "TESTING" is present in the $list array. If yes - just echo "present", if not - echo "not present". What is the best way to do this?
I know how to search a web page and extract text parts from it.
$curl = curl_init('http://testing-ground.scraping.pro/textlist'); // cURL
setup
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // return the transfer
page as a string
curl_setopt($curl, CURLOPT_HEADER, TRUE);
$page = curl_exec($curl); // executing the request
if(curl_errno($curl)) // check for execution errors
{
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl); // closing the connection
$regex = '/<div id="title">(.*?)<\/div>/s'; // extracting the needed part
if ( preg_match($regex, $page, $list) ) // search matches of $page with
$regex
echo $list[0];
else
print "Not found";