PHP Classes

File: ArticleTest.php

Recommend this page to a friend!
  Classes of Stefan Kientzler   PHP Generate Json LD   ArticleTest.php   Download  
File: ArticleTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Generate Json LD
Generate metadata for HTML pages in JSON-LD format
Author: By
Last change: added phpunit tests
PHP 7.4 / github wiki
Date: 2 years ago
Size: 1,239 bytes
 

Contents

Class file image Download
<?php
use SKien\JsonLD\JsonLDArticle;
// the autoloader will find all needed files...
require_once 'autoloader.php';

$oJsonLD = new JsonLDArticle();

$oJsonLD->setPublisher('Sportsclimbing SC');
$oJsonLD->setLogo("http://localhost/packages/JsonLD/elephpant.png");
$oJsonLD->setInfo('New Outdoor climbing facility opened', '... and the article...', new DateTime('2020-05-12'), new DateTime('2020-05-13 22:13:42'));
$oJsonLD->setAuthor('Stefanius');
$oJsonLD->addImage('elephpant.png'); // use bigger image - only for test purposes to avoid warning from test tool
?>
<!DOCTYPE html>
<html>
<head>
<title>Json LD Generator</title>
<!-- insert the tag in the head section of the document -->
<?php echo $oJsonLD->getHTMLHeadTag(false);?>
</head>
<body>
    <h1>Json LD Generator - Article</h1>
    <p>You can copy generated JsonLD script to test it in
        <a target="_blank" href="https://search.google.com/structured-data/testing-tool">
            https://search.google.com/structured-data/testing-tool
        </a>
    </p>
    <textarea style="font-family: 'Courier'; width: 100%; white-space: nowrap;" rows="50" spellcheck="false"><?php echo $oJsonLD->getJson(true);?></textarea>
</body>
</html>