1

Sourcecode:

<!DOCTYPE HTML>
<html>
    <head>
        <title>Just an example title</title>
        <meta charset="utf-8">
        <meta name="description" content="A powerful description.">
        <meta name="twitter:title" content="*this should be same as title*">
        <meta name="twitter:description" content="*this should be same as description*">
[...]

So my question is, is there a way to use php so, that it "copies" the page title and paste it on other html tags? I'm really new to php and would love to get this done. Thank you for any help.

Niclas
  • 61
  • 8

1 Answers1

2

You can read a file in your web ($file stores the location of that file) and search for any tag named title. This returns an array with all the elements with that tag. In this case it will only return one element, the title itself.

<?php

    $file = $DOCUMENT_ROOT. "yourfile.html";
    $doc = new DOMDocument();
    $doc->loadHTMLFile($file);

    $xpath = new DOMXpath($doc);

    $elements = $xpath->query("//*[@title]");

    echo $elements[0];

?>

Check the DomXPath documentation for more info.

driconmax
  • 956
  • 1
  • 18
  • 32