javascript - 如何使用php读取html中标签的id?

标签 javascript php jquery html dom

$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/

相关文章:

ruby-on-rails - 为什么 Rails 3 中的 AJAX 如此困难?或者说,我做错了什么?

javascript - 在CSS中隐藏菜单项

javascript - session 存储值未显示在第二页中

javascript - 如何让 Node 在layout.ejs上拾取?

javascript - 跨多个文件将大型 typescript 文件拆分为模块

php - mysql更新多列一行单语句与多语句

php - CMS 和框架有什么区别?以及如何根据某些要求在它们之间进行选择?

javascript - 在mysql中用多维数组存储$_POST

javascript - Jquery 小部件的问题

Javascript - 数组覆盖