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


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

$oJsonLD = new JsonLDArticle();

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