PHP code example of vnetby / schemaorg

1. Go to this page and download the library: Download vnetby/schemaorg library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vnetby / schemaorg example snippets


use Vnet\Schemaorg\Types\Thing\Intangible\Trip\TouristTrip;
use Vnet\Schemaorg\Types\Thing\Place\AdministrativeArea\City;

$type = TouristTrip::fromArray([
    'name' => 'Trip name',
    'description' => 'Trip description',
    'itinerary' => [
        City::fromArray(['name' => 'City 1']),
        City::fromArray(['name' => 'City 2']),
        City::fromArray(['name' => 'City 3']),
        City::fromArray(['name' => 'City 4']),
        City::fromArray(['name' => 'City 5']),
    ]
]);

$type->setProp('name', 'Trip name')->setProp('description', 'Trip description');

use Vnet\Schemaorg\Types\Thing\Intangible\Trip\TouristTrip;
use Vnet\Schemaorg\Types\Thing\Place\AdministrativeArea\City;

$type = TouristTrip::fromArray([
    'name' => 'Trip name',
    'description' => 'Trip description',
    'itinerary' => [
        City::fromArray(['name' => 'City 1']),
        City::fromArray(['name' => 'City 2']),
        City::fromArray(['name' => 'City 3']),
        City::fromArray(['name' => 'City 4']),
        City::fromArray(['name' => 'City 5']),
    ]
]);

$jsonld = Jsonld::create($type);

$jsonld->toArray(); // returns an array of json-ld markup
$jsonld->generate(); // generates a string with json-ld markup
$jsonld->render(); // outputs the json-ld markup

use Vnetby\Schemaorg\DataTypes\DataDate;
use Vnetby\Schemaorg\Types\Thing\Event\Event;

$event = new Event;
$event
    ->setEndDate(new DataDate('23-03-1995'))
    ->setStartDate(new DataDate('23-03-1995'));

$date = $event->getStartDate();

use Vnetby\Schemaorg\DataTypes\DataDate;
use Vnetby\Schemaorg\Types\Thing\Event\Event;

$event = new Event;
$event
    ->setEndDate('23-03-1995')
    ->setStartDate('23-03-1995');

$date = $event->getStartDate();