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