3
我想通过使用simplehtmldom.sourceforge.net来操纵HTML代码。这是我迄今为止。我可以创建一个新文件或将index.html改为index.php并从index.html复制头标记。问题是,我怎样才能插入链接标签:如何使用SimpleHtmlDom在HTML头标签之间插入链接标签
<link href="style.css" rel="stylesheet" type="text/css" />
之间的头标签?
<?php
# create and load the HTML
include('simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('D:\xampp\htdocs\solofile\index.html');
$indexFile ='index.php';
$openIndexFile = fopen($indexFile,'a');
//find head tag
foreach($html->find('head') as $e)
{
$findHead = $e->outertext;
fwrite($openIndexFile, "\n" .$findHead. "\n");
}
+1 for spoonryeding – Gordon 2011-01-21 10:48:32