$handle = fopen("exercise/Exercise.php", "r"); //file to be read
$file = fread($handle ,8192);
print("Size of the file: ".strlen($file)."\n");
$html =$file;
$dom = new DOMDocument;
$dom->loadHTML($html);
$dom->getElementsByTagName("font")->item(0);
fclose($handle);
但是这段代码不起作用,我收到错误
Warning: DOMDocument::loadHTML(): htmlParseStartTag: misplaced <head> tag in Entity, line: 3 in C:\xampp\htdocs\csstutorial.php on line 17
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 34 in C:\xampp\htdocs\csstutorial.php on line 17
我不知道我哪里错了?我应该使用 $dom->load($html);
而是这个。
Exercise.php 代码:
<html>
<title>Exercise </title>
<head >
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<font font face='Calibri'>
<div id="1">
<?php
echo "<p> <B>Question 1) </B>Go to this address "
?>
<a href="https://loans.icicibank.com/personal-loan.html?WT.mc_id=PL_Applyonline&_ga=1.98179290.431324016.1423809984" target='_blank' style="text-decoration: none">ICICI Personal Loans</a>
<?php
echo nl2br("and apply for loan as 4 cases Type of employment:
a.) Salaried
b.) Salaried Employed Professional
With the help of")
?>
<a href="Salary.xlsx" download style="text-decoration: none">Excel sheet</a>
<?php </font> ?>
</p></div>
</body>
</html>
我需要获取<div>
的id标签。最好的方法是什么。
最佳答案
试试这个 $doc->getElementById('div-id')->item(0)
关于javascript - 如何使用php读取html中标签的id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29092569/