I'm trying to extract emails, names and phone numbers from my html table and use these details in order to send an automatic email reply.
For some reason, I get a fatal error saying: Call to undefined function file_get_html() in http://itecdigital.org.uk/2015/430926/BeautyFactoryBooking/admin.php on line 3
My code for the html Dom parser:
<?php
$html = file_get_html('http://itecdigital.org.uk/2015/430926/BeautyFactoryBooking/admin.php');
$dom = new DOMDocument();
$dom->loadHTML($html);
$elements = $dom->getElementsByTagName('tr');
//Loop through each row
foreach ($rows as $row) {
//Loop through each child (cell) of the row
foreach ($row->children() as $cell) {
echo $cell->plaintext; // Display the contents of each cell - this is the value you want to extract
}
}
?>
Can anyone see whats wrong with this?
My html code for the table is as follows:
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>Id</th><th>First Name</th><th>Last Name</th><th>Email Address</th><th>Phone Num</th><th>Treatment</th><th>Date</th><th>Time</th><th>Message</th><th>Reply</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:100px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "
";
}
}
$servername = "#";
$username = "#";
$password = "#";
$dbname = "#";
try {
$conn = new PDO("mysql: host=$servername; dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT Booking_request_form.id_booking, Client_Information.first_name, Client_Information.last_name, Client_Information.email_address, Client_Information.phone_number, Booking_request_form.treatment, Booking_request_form.date, Booking_request_form.time, Booking_request_form.message FROM Booking_request_form INNER JOIN Client_Information WHERE Client_Information.id_client=Booking_request_form.client_fk");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
Is there an easy fix to this?