PHP Classes

File: BusinessTest.php

Recommend this page to a friend!
  Classes of Stefan Kientzler   PHP Generate Json LD   BusinessTest.php   Download  
File: BusinessTest.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: 2,228 bytes


Class file image Download
use SKien\JsonLD\JsonLD;


$oJsonLD = new JsonLDLocalBusiness('FoodEstablishment'); // 'SportsActivityLocation');
$oJsonLD->setInfo('Sportsclimbing SC', '', '12345 67890');
$oJsonLD->setDescription('Sportsclimbinbg indoor and outdoor for everyone');
$oJsonLD->setAddress('Street 12', '12345', 'MyTown', '', 'Germany');
$oJsonLD->setLocation('Sportsclimbing SC', 48.3365629, 7.8447896, ',7.8447896,156m/data=!3m1!1e3!4m5!3m4!1s0x47912e4949b57841:0xc26f08dacee0a1a9!8m2!3d48.3367173!4d7.8441243');
$oJsonLD->addImage('elephpant.png'); // usually you should use a bigger image - only for test purposes to avoid warning from test tool
$oJsonLD->setProperty('menu', '', JsonLD::URL);
$oJsonLD->addOpeningHours([1,1,1,1,1,0,0], '8:00', '12:00');
$oJsonLD->addOpeningHours([1,1,0,0,1,0,0], '13:00', '17:30');

// and create department...
$oDepartment = new JsonLDLocalBusiness('Organization', true);
// at least the @id MUST be other than the base-id!
$oDepartment->setInfo('Sportsclimbing SC - Outdoor Center', '');
$oDepartment->setAddress('Another street', '12345', 'MyTown');

<!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 - Local Business</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>