mardi 29 octobre 2019

Change Page-Title with PHP

Im completely new to PHP and have a simple questions. The first thing I have to solve is to change the Page-Title on my HTML-Website with PHP. Yes it has to be PHP or something that runs before the HTML is showed in browser. The Page-Title-Text that I want to choose as Title is located on my HTML page like <h4 class="fn"> Title of my Page </h4>. I got smth like this:

<?php
    $doc= DOMDocument::loadHTMLFile('index.html');
    $doc= new DOMDocument();
    $titelelem=$doc->getElementsByTagName('title')->item(0);
    $realtitleelem=$doc->getElementsByTagName('h4')->item(0);
    $realtitle=$realtitelelem->innerHTML;
    $titelelem->innerHTML=$realtitle;

    echo $doc->saveXML();
    echo $doc->saveHTML();
?>

No clue if smith is right here. Im not even sure how I load my html as new DOM.




Aucun commentaire:

Enregistrer un commentaire