Как вставить теги ссылок между тегами заголовка в HTML с помощью SimpleHtmlDom

Я пытаюсь манипулировать HTML-кодами с помощью simplehtmldom.sourceforge.net . Это я до сих пор. Я мог бы создать новый файл или превратить index.html в index.php и скопировать главный тег из index.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"); } в <?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"); } 

Из документации (Раздел: Как получить доступ к атрибутам элемента HTML? / Советы):

 // Append a element $e->outertext = $e->outertext . '<div>foo<div>'; 

Что вы можете использовать следующим образом:

 $e = $html->find('head')->innertext; // Should take all HTML inside <head></head> w/o <head></head $e = $e.'<link href="style.css" rel="stylesheet" type="text/css" />'; // inserting the CSS at the end of what's inside <head></head> 

Я не пытался, но, может быть (в зависимости от класса), вам может понадобиться сделать первую строку в 2.

 $f = $html->find('head'); $e = $f->innertext; 

Но вы поняли, верно? 😉