Just trying to edit/modify the head tag in order to add something inside with DOM and PHP.
$dom = new DOMDocument();
$dom->loadHtml(utf8_decode($html), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
for($i=0; $i<count($r);$i++)
{
// Prepare the HTML to insert
Here I want to add $var inside head tag (at the end if possible)
}
return $dom->saveHTML();
Everytime I tried, I have LENGHT=0 as the result of var_dump.
Edit: I don't want to edit an existing tag. I want to add a new one. To be more specific, I need to add OG meta tag for Facebook sharing.
Edit2 as requested :
Before
<head>
<meta blabla>
<title></title>
</head>
<body>
<h1></h1>
</body>
After
<head>
<meta blabla>
<title></title>
<meta new1>
</head>
<body>
<h1></h1>
</body>
But need to be edit via DOMDocument in PHP...