I am trying to render an HTML page as PDF in using DOMPDF version 0.8 on CodeIgniter running on Windows 7 64 bit. My development machine runs PHP 7 on XAMPP on a Windows 10 Pro but the production server runs PHP 5.6 on Windows 7 professional 64bit.
I realize that when I run the application on my local machine, everything works well and the PDF is properly generated with the images and styles properly displayed in place. But when I deploy to the production machine, the styles and the images dont render properly again. The images dont display and the styles are not rendered.
Please I will appreciate any suggestions to resolve this issue
Here are some parts of my codes below:
//Application/libraries/pdf.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once("./vendor/dompdf/dompdf/src/autoloader.php");
use Dompdf\Dompdf;
class Pdf
{
public function generate($html, $filename='', $stream=TRUE, $paper = 'A4',
$orientation = "landscape")
{
$dompdf = new DOMPDF();
$dompdf->loadHtml($html);
$dompdf->setPaper($paper, $orientation);
$dompdf->render();
if ($stream)
{
$dompdf->stream($filename.".pdf", array("Attachment" => 1));
}
else
{
return $dompdf->output();
}
}
}
//Application/controllers/report.php
...some code removed for brevity
$this->load->library('pdf');
$html=$this->load->view('parts/pdf-head',NULL,true);
$html.=$this->load->view('admin/reports/periodic/pdf',['results'=>$_SESSION['students_result']],true);
$this->pdf->generate($html,'report');
//Application/views/admin/reports/periodic/pdf.php
<?php
if(empty($results))
{
echo "<div class='alert alert-danger'><span class='fa fa-warning'></span> No result found in record for the selected parameters</div>";
}
else
{
foreach($results['scores'] as $student=>$scores)
{
?>
<table class="table table-bordered" style="padding: 10px">
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo img(['src'=>"style-resources/logo2.png", 'width'=>"50px"]);?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo $results['campus'];?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo $results['title'];?>
</td>
</tr>
<tr class="tr-row2">
<th colspan="10" style="text-align: left;">
<?php echo strtoupper($scores['student_info']['student_names']);?>
</th>
<td colspan="6">
<?php echo $scores['student_info']['class'].', '.$scores['student_info']['class_arm']; ?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="7" style="text-align: right">Number of class contacts </td><td style="text-align: left"><?php echo $scores['student_info']['attendance'];?></td><td colspan="7" style="text-align: right">Student's Attendance</td><td style="text-align: left"><?php echo $scores['attendance_score'];?></td>
</tr>
<tr class="tr-row2">
<th>C.A.1 (10%)</th><td><?php echo $scores['ca1']; ?></td><th>C.A.2 (10%)</th><td><?php echo $scores['ca2']; ?></td><th>Classwork (15%)</th><td><?php echo $scores['classwork']; ?></td><th> Attendance (5%)</th><td><?php echo $scores['attendance_score'];?></td><th>EXAM (60%)</th><td><?php echo $scores['exam']; ?></td><th>TOTAL (100%)</th><td><?php echo $scores['total'];
?></td><th>Grade</th><td><?php echo $scores['grade']; ?></td><th>POSITION</th><td><?php $this->load->helper('ordinalize'); echo ordinalize(array_search($scores['total'],$_SESSION['result_total'])+1); ?></td>
</tr>
<tr class="tr-row2">
<th colspan="3">Highest Score</th><td><?php echo max($_SESSION['result_total']); ?></td><th>Lowest Score</th><td><?php echo min($_SESSION['result_total']); ?></td><th>Class Average</th><td><?php echo array_sum($_SESSION['result_total'])/count($_SESSION['students_result']['scores']) ?></td><th colspan="3">Effort</th><td colspan="5" style="text-align: left"><?php echo $scores['effort'];?> </td>
</tr>
<tr>
<th colspan="6">
<table class="table table-striped table-bordered">
<tr class="tr-row2">
<td colspan="2" style="text-align: center">
Accomplishments for the Term
</td>
</tr>
<tr class="tr-row2">
<th>Exercise/Activity</th>
<th>Score</th>
</tr>
<?php
if(empty($scores['scores'][1]))
{
echo "<tr class='tr-row2'><td colspan='2'><em> No lesson exercise found for this student</em></td></tr>";
}
else {
foreach ($scores['scores'][1] as $a => $b) {
if ($a != 'total') {
echo "<tr class='tr-row2'><th>" . $a . "</th><td>" . $b . "</td></tr>"; ?>
<?php }
}
}
?>
<tr class="tr-row2"><th colspan="2" style="text-align: center">Summary of report</th></tr>
<tr class="tr-row2">
<td colspan="2"><em><?php echo $scores['comment']; ?></em></td>
</tr>
</table>
</th>
<th colspan="10">
<table class="table table-striped">
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Skills/Strengths demonstrated
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['skills'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Observed Weakness(es)
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: Left">
<em><?php echo $scores['student_info']['weaknesses'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Remedial steps taken
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['remedies'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Further improvement steps to be taken
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['further_actions'];?></em>
</td>
</tr>
</table>
</th>
</tr>
<tr class="tr-row2">
<th colspan="4" style="text-align: right">Educator's Name</th><td colspan="4" style="text-align: left"><em><?php echo $results['educator']; ?></em></td><th colspan="4" style="text-align: right">Educator's Signature</th><td colspan="4"></td>
</tr>
<tr class="tr-row2">
<th colspan="4" style="text-align: right">Coordinator's Name</th><td colspan="4" style="text-align: left"><em><?php echo $results['coordinator'];?></em></td><th colspan="4" style="text-align: right">Coordinator's Signature</th><td colspan="4"></td>
</tr>
</table>
<?php }
}
.HTACCESS file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
in this check your RewriteBase.
Then Check your application/config/config.php for $config['base_url'] = 'http://localhost/project_name'; line of code.
Related
<?php
$data1 ='<div id="prnittab">
<table width="100%" style="font-size:13px; margin-top:11px;border:solid 1px #333333;border-
bottom: 0px;">
<tr>
<td width="100%" style="padding:20px;">
<table width="100%" style="border:0px;">
<tr>
<td width=20% height="5px;" colspan="2"><img src="https://www.fillmurray.com/640/360"
width="220" height="75" alt="logo" /></td>
</tr>
<tr>
<td colspan="2" height="10"></td>
</tr>
<tr>
<td width="50%" align="left" valign="top style="font-size:16px;font-weight:bold;padding-left:15px;">Report Data</td>
<td width="50%" align="right" valign="top"
style="font-size:12px;font-weight:bold;padding-right:15px;">Monday, September 23, 2019</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" style="border-collapse: collapse;border: 1px solid #333333;">
<tr height="30">
<td align="left" style="font-size:12px;font-size:12px;font-weight:bold;padding-left:10px;">XYZ</td>
<td align="left"
style="font-size:12px;font-size:12px;font-weight:bold;height:20px !important;padding-right:10px;">Check
</td>
<td align="right"
style="font-size:12px;font-size:12px;font-weight:bold;height:20px !important;padding-right:10px;">
$540.00</td>
</tr>
</table>
</div>';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $data1;
I want to convert html file into pdf using mpdf class. working well but the count > 30 the page rotating no display ,
<?php
include("connection.php");
$phase=mysql_query("select * from session where status=1");
$phasee = mysql_fetch_array($phase);
$mindate = $phasee['st_date'];
$maxdate = $phasee['end_date'];
$query_omr = mysql_query("SELECT * from sit_details a,staff_details b where b.staff_code=a.staff_code and a.val_center=".$_GET['num']);
$staffrowdet = mysql_fetch_array($query_omr);
$query_exam_session = mysql_query("SELECT * from exam_session");
$row_exam_session = mysql_fetch_array($query_exam_session);
$randm=rand(100001,999999);
$text_page='
<style>
table {
width:1000px;
font-family:Times New Roman, Times;
border-collapse: collapse;
text-align:justify;
padding:2px;
font-size:12px;
text-transform: uppercase;
}
td, th {
height:30px;
text-transform: uppercase;
padding:2px;
}
</style>
<table id="simple-table" >
<tr><td colspan="2">
<table>
<tr>
<td rowspan="3"><img src="assets/images/logo.gif" width="80px" /></td>
<td align="center" style="font-size:20px"><strong>Heading1 </strong></td>
</tr>
<tr>
<td align="center" style="font-size:16px"><strong>Heading2 - '. $row_exam_session['session'].' </strong> </td>
</tr>
<tr>
<td align="center" style="font-size:14px"><strong>DETAIL</strong></td>
</tr>
</table>
</td></tr>
<tr><td colspan="2">
<table id="dynamic-table" class="table table-striped table-bordered table-hover" width="900" align="left">
<tr>
<th colspan="6" style="font-size:14px" align="left">PERIOD : FROM <u>'.$mindate .' </u> TO <u>'.$maxdate.' </u> </th>
</tr>
<div style="width:50px;height:50px;border:1px solid #000;"></div>
</table>
</td></tr>
<tr>
<td>
<strong><caption> Form Details</caption> </strong>
<table id="dynamic-table" class="table table-striped table-bordered table-hover" border="1" style="page-break-inside: avoid"> <tr bgcolor="#CCCCCC" >
<th align="center" width="50px"><label class="control-label bolder blue">Sl.No </label></th>
<th align="center" width="100px"><label class="control-label bolder blue">Staff ID </label></th>
<th align="left" width="100px"><label class="control-label bolder blue"> Staff Name</label></th>
<th align="left" width="100px"><label class="control-label bolder blue"> Designation </label></th>
</tr>';
$c1=0;
while($row_dummy = mysql_fetch_array($query_omr)) {
$text_page=$text_page.'
<tr>
<td align="center"><h3>'. $c1 .'</h3></td>
<td align="center"><h3>'. $row_dummy['staff_code'].'</h3></td>
<td align="left"><h3>'. $row_dummy['staff_name'].'</h3></td>
<td align="left"><h3>'. $row_dummy['staff_designation'].'</h3></td>
</tr>';
$c1++;
}
$text_page=$text_page.'
<tr>
<table >
</tr>
</table>
</table>
</td>
</tr>
<table id="dynamic-table" class="table table-striped table-bordered table-hover" border="1" width="800" >
<tbody>
<tr>
<th align="center" width="300px" ></th> <br/>
<th align="center" width="150px">Post Held</th>
<th align="center" width="250px">Name</th>
<th align="center" width="50px">Signature</th>
</tr>
<tr>
<td> </td>
<td align="center" height="70"><strong> <br/> Officer / <br/> Coordinator </strong> </td>
<td height="70"></td>
</tr>
<tbody>
<td align="right" width="300px" valign="bottom" rowspan="2" > </td>
</table>
</table>
<table>
<tr><td align="left"><h4>'.$randm.'</h4></td><td align="right"><h4>'.date('d-m-Y H:i:s').'</h4></td></tr>
</table>
';
//echo $text_page;
//exit;
ob_end_clean();
ini_set('memory_limit', '500000M');
include("MPDF57/mpdf.php");
//$mpdf = new mPDF('c', 'A4-L','0', '0', '10', '10','10', '10');
$mpdf = new mPDF(
'', // mode - default ''
'A4', // format - A4, for example, default ''
0, // font size - default 0
'', // default font family
10, // margin_left
10, // margin right
5, // margin top
0, // margin bottom
5, // margin header
5, // margin footer
'P' // L - landscape, P - portrait
);
$mpdf->autoPageBreak = true;
$mpdf->AddPage();
$fname=$_GET['num'].".pdf";
$mpdf->SetWatermarkImage('assets/images/logo.jpg');
$mpdf->setFooter('{PAGENO}');
$mpdf->showWatermarkImage = true;
$mpdf->WriteHTML($text_page);
$mpdf->Output($fname, 'D');
exit;
?>
the pdf downloaded, but the count<30 if the rowcount>30 the page not responding. how to solve this error. i cannot find out the solution. kindly suggest any other mpdf sample program which is matching my requirement.
I tried to do it but the big problem is foreach here i have the foto:
Problem
Here is my table picture
Here is the code but still have problem:
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="6" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<tr height="20">
<td colspan="3" rowspan="5" height="120" ></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
</tbody>
</table>
</div>
How can i do it so that when i use foreach it will insert new td and the vertical Here is my title will be there?
ok, so you're using php here's a very basic example on how you can do that, i'm assuming you already did query and the fetching part, and this is a guess of your data structure, you can adjust it to your liking :
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="100%" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<?php
foreach($data as $key => $value){
echo '<tr height="20">';
echo '<td colspan="3">'.$value['name'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['article'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['price'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['date'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
here's a fiddle : https://jsfiddle.net/kkpjx328/
I hope this helps .
PS : on your next question, please consider adding the data structure and if possible, an example or code sample of what you've tried so far so we can provide more specific answers
Am currently developing a web application which does the process of invoice etc.
Customer is using dot matrix printer to print invoice sheet. They said the requirement in printing as if there is more than 5 items in a sheet the rest should come as next sheet.
I have made that using PHP but i don't know how to print the next sheet in next page. It just prints as usual in sequence which results in a sheet printed in 2 pages. Any help or ideas will be appreciated. Below is the code how i generated sheet.
Thanks
<script type="text/javascript">
function printPage(){
var divElements = document.getElementById('printDataHolder').innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML="<link rel='stylesheet' href='css/common.css' type='text/css' /><body class='bodytext'>"+divElements+"</body>";
window.print();
document.body.innerHTML = oldPage;
}
</script>
<?php
$limit=5;
$cnt=0; // for table header and footer
$cnt2=1;// for no of rows count to print total values in end
$total=0;
?>
<div id="contentHolder" align="center">
<input type="button" value="Print" class="btnclass" onclick="printPage()" /> <input type="button" class="btnclass" value="Click to Proceed" style="width:100px;" onclick="Javascript:window.location.href='invoice.php';" />
<br />
<div id="printDataHolder">
<?php while($data=mysql_fetch_array($invcontents)){ ?>
<?php if($cnt==0){ ?>
<table width="800" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #4E9A91;">
<tr>
<td height="29" colspan="4" style="font-size:22px; padding-left:10px;"><strong>OvalTechnologies</strong></td>
</tr>
<tr>
<td colspan="4" style="padding-left:10px;"><?php echo($branchdetails['address']); ?></td>
</tr>
<tr>
<td height="19" colspan="4" style="padding-left:10px;">Website : www.ovaltechnologies.in Phone No : <?php echo($branchdetails['phoneno']); ?></td>
</tr>
<tr>
<td height="12" colspan="4" style="border-bottom:1px solid #4E9A91;"> </td>
</tr>
<tr>
<td height="28" colspan="3" style="padding-left:10px;">Customer Name : <?php echo($invtotal['customername']); ?></td>
<td width="226"> </td>
</tr>
<tr>
<td width="309" height="28" style="padding-left:10px;border-bottom:1px solid #4E9A91;">Invoice No : <?php echo($invoiceid); ?></td>
<td colspan="2" style="border-bottom:1px solid #4E9A91;">Paid As : <?php echo($invtotal['paidas']); ?></td>
<td style="border-bottom:1px solid #4E9A91;">Date : <?php echo(getonlydatefromdatetime(changefromdbdate($invtotal['invoicedate']))); ?></td>
</tr>
<tr>
<td height="28" class="rowborder" style="padding-left:10px;"><strong>Item Name</strong></td>
<td width="136" class="rowborder"><strong>Rate</strong></td>
<td width="129" class="rowborder"><strong>Qty</strong></td>
<td class="rowborder"><strong>Amount</strong></td>
</tr>
<?php } ?>
<tr>
<td align="center" height="28" style="padding-left:10px;"><?php echo($data['item']); ?> : <?php echo($data['brand']." "); ?><?php echo($data['type']); ?></td>
<td align="center"><?php echo($data['billedamount']); ?></td>
<td align="center"><?php echo($data['quantity']); ?></td>
<td align="center"><?php echo($data['billedamount']*$data['quantity']); ?></td>
</tr>
<?php
if($cnt2==$invcount){//printing emptylines to fill up page
for($i=$cnt+1;$i<$limit;$i++){
?>
<tr>
<td height="28" style="padding-left:10px;"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
}
}//printing emptylines to fill page ends
?>
<?php if($cnt==$limit-1 || $cnt2==$invcount){ ?>
<?php if($invtotal['transport']!="") {?>
<tr>
<td style="padding-left:10px; border-top:1px solid #4E9A91;" class="rowborder" height="28">Transport : <?php echo($invtotal['transport']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Transport Cost : <?php echo($invtotal['transportcost']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Destination : <?php echo($invtotal['destination']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"> </td>
</tr>
<?php } ?>
<tr>
<td height="28" class="rowborder" style="border-top:1px solid #4E9A91;"> </td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"><?php if($invtotal['transport']!="") {if($invtotal['addtransport']=="no"){echo("Transport Cost Not Added");}}?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Total</td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"><?php echo($invtotal['totalamount']);?></td>
</tr>
<tr>
<td height="28"> </td>
<td> </td>
<td> </td>
<td align="center">Invoice Done By</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table><br />
<?php } ?>
<?php
$cnt++;
$cnt2++;
if($cnt==$limit){
$cnt=0;
}
} ?>
</div>
</div>
<?php
} ?>
do not see such options in http://www.php.net/manual/en/function.printer-set-option.php
but you can have look around the functions here http://www.php.net/manual/en/ref.printer.php
printer_start_doc — Start a new document
printer_start_page — Start a new page
Hi I'm trying to parse a Wikipedia document in which there is a table called "infobox biota" with this structure. I'm trying to get the following table data and classes of the following characteristics
Kingdom:
Phylum:
Subphylum:
Class:
Order:
Family:
<table class="infobox biota" style="text-align: left; width: 200px; font-size: 100%">
<tbody><tr>
<th colspan="2" style="text-align: center; background-color: rgb(211,211,164)">Rabbit</th>
</tr>
<tr>
<td colspan="2" style="text-align: center"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Rabbit_in_montana.jpg/250px-Rabbit_in_montana.jpg" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Rabbit_in_montana.jpg/375px-Rabbit_in_montana.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Rabbit_in_montana.jpg/500px-Rabbit_in_montana.jpg 2x" height="222" width="250"></td>
</tr>
<tr>
<th colspan="2" style="text-align: center; background-color: rgb(211,211,164)">Scientific classification</th>
</tr>
<tr>
<td>Kingdom:</td>
<td><span class="kingdom" style="white-space:nowrap;">Animalia</span></td>
</tr>
<tr>
<td>Phylum:</td>
<td><span class="phylum" style="white-space:nowrap;">Chordata</span></td>
</tr>
<tr>
<td>Subphylum:</td>
<td><span class="subphylum" style="white-space:nowrap;">Vertebrata</span></td>
</tr>
<tr>
<td>Class:</td>
<td><span class="class" style="white-space:nowrap;">Mammalia</span></td>
</tr>
<tr>
<td>Order:</td>
<td><span class="order" style="white-space:nowrap;">Lagomorpha</span></td>
</tr>
<tr>
<td>Family:</td>
<td><span class="family" style="white-space:nowrap;">Leporidae<br>
<small>in part</small></span></td>
</tr>
<tr>
<th colspan="2" style="text-align: center; background-color: rgb(211,211,164)">Genera</th>
</tr>
<tr>
<td colspan="2" style="text-align: left">
<div>
<table style="background-color:transparent;table-layout:fixed;" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr valign="top">
<td>
<div style="margin-right:20px;">
<p><i>Pentalagus</i><br>
<i>Bunolagus</i><br>
<i>Nesolagus</i><br>
<i>Romerolagus</i></p>
</div>
</td>
<td>
<div style="margin-right: 20px;">
<p><i>Brachylagus</i><br>
<i>Sylvilagus</i><br>
<i>Oryctolagus</i><br>
<i>Poelagus</i></p>
</div>
</td>
</tr>
</tbody></table>
</div>
</td>
</tr>
</tbody></table>
Here is my attempt to parse and obtain the kingdom,phylum,subphylum,class,order and family of a rabbit with the table structure. However I get a the following Array ( [Kingdom:] => [Phylum:] => [Subphylum:] => [Class:] => [Order:] => [Family:] => [
Pentalagus
Bunolagus
Nesolagus
Romerolagus
] => )
it doesnt fill in the array with the data for the rabbit. also it give me a parse error in the line shown below, what can be wrong?
<?php
//require"mydb.php";
header('Content-type: text/html; charset=utf-8'); // this just makes sure encoding is right
include('simple_html_dom.php'); // the parser library
$html = file_get_html('http://en.wikipedia.org/wiki/Rabbit');
$table = $html->find('table.infobox');
$data = array();
foreach($table[0]->find('tr') as $row)
{
$td = $row->find('> td');
if (count($td) == 2)
{
$name = $td[0]->innertext;
$text = $td[1]->find('a')[0]->innertext; //PARSE ERROR IS GIVEN HERE, after the find('a')[0], taking off the array takes away the error but just me no results
$data[$name] = $text;
}
}
print_r($data);
?>
$text = $td[1]->find('a')[0]->innertext;
In this line you are dereferencing a function. This is only available in PHP 5.4 or later. Try this instead:
$td = $td[1]->find('a');
$text = $td[0]->innertext;