There are two different tags in the HTML which are row0-1
and row1-1
. I want to search for the contents in the HTML called row1Time
from the row1-1
tag.
Here's and example HTML:
<li class="zc-ssl-pg" id="row0-1" style="">
<span id="row1Time" class="zc-ssl-pg-time">4:00 PM</span>
<li class="zc-ssl-pg" id="row1-1" style="">
<span id="row1Time" class="zc-ssl-pg-time">3:00 PM</span>
Here's my PHP:
<?php
$errmsg_arr = array();
$errflag = false;
$link;
function db_connect()
{
define('DB_HOST', 'localhost');
define('DB_USER', 'myusername');
define('DB_PASSWORD', 'mypassword');
define('DB_DATABASE', 'mydbname');
$errmsg_arr = array();
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link)
{
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db)
{
die("Unable to select database");
}
}
$links = $row['links'];
include ('simple_html_dom.php');
$html = file_get_html($links);
//echo $row['links'];
$base = $row['links'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);
// Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($str);
//get all category links
/*foreach($html_base->find('a') as $element) {
echo "<pre>";
print_r( $element->href );
echo "</pre>";
}*/
//$html_base->clear();
//unset($html_base);
$time1 = $html->find('span[id=row1Time]', 0)->plaintext;
echo '<span id="time1">'.$time1.'</span> - ';
?>
When I tried to parse the contents from the HTML using this:
$time1 = $html->find('span[id=row1Time]', 0)->plaintext;
echo '<span id="time1">'.$time1.'</span> - ';
The return output I get is from the tags row0-1
with row1Time
:
4:00 PM
I want to search for the contents in the HTML from the tags row1-1
with row1Time
to get the return contains 3:00 PM
. Can you please help me get those contents using simple_html_dom
?