我的代碼是這樣的,它將訪問所有的DOM元素。現在我想在他們旁邊添加行號。任何人都可以請幫忙。謝謝。有沒有辦法在每個DOM標籤旁添加行號?
<?php
$dom = new domDocument;
// load the html into the object
$dom->loadHTMLFile('$url');
// keep white space
$dom->preserveWhiteSpace = true;
// nicely format output
$dom->formatOutput = true;
//get element by tag name
$htmlRootElement = $dom->getElementsByTagName('html');
$new = htmlspecialchars($dom->saveHTML(), ENT_QUOTES);
echo '<pre>' .$new. '</pre>';
?>
上面的代碼不會輸出任何行號。我想要做這樣的事情。
<!DOCTYPE html>
1.<html>
2.<head>
3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4. <title></title>
5.</head>
6.<body>
7.</html>
請任何建議。謝謝。
這真的很有幫助。作品完美。太感謝了。 – user1825190
太棒了,很高興提供幫助。謝謝! – chwagssd