PHP code example of evabee / schema-org-json-ld

1. Go to this page and download the library: Download evabee/schema-org-json-ld 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/ */

    

evabee / schema-org-json-ld example snippets


$product = new Product(
	name: "Executive Anvil",
	image: [
		"https://example.com/photos/1x1/photo.jpg",
		"https://example.com/photos/4x3/photo.jpg",
		"https://example.com/photos/16x9/photo.jpg"
	],
	description: "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
	sku: "0446310786",
	brand: new Brand(
		name: "ACME (tm)",
	),
	mpn: "ACME0444246625",
	weight: new QuantitativeValue(
		value: 55.67,
		unitCode: "LBR"
	),
	offers: [
		new Offer(
			url: "https://example.com/anvil",
			priceCurrency: "USD",
			price: 119.99,
			itemCondition: OfferItemCondition::NewCondition,
			availability: ItemAvailability::InStock,
			shippingDetails: [
				new OfferShippingDetails(
					shippingDestination: new DefinedRegion(
						addressCountry: "US",
						addressRegion: [ "CA", "NV", "AZ" ]
					),
					shippingRate: new MonetaryAmount(
						value: 3.49,
						currency: "USD",
					),
					deliveryTime: new ShippingDeliveryTime(
						handlingTime: new QuantitativeValue(
							unitCode: "DAY",
							minValue: 0,
							maxValue: 1
						),
						transitTime: new QuantitativeValue(
							unitCode: "DAY",
							minValue: 1,
							maxValue: 5
						)
					)
				),
				new OfferShippingDetails(
					shippingDestination: new DefinedRegion(
						addressCountry: "US",
						addressRegion: [ "HI" ]
					),
					shippingRate: new MonetaryAmount(
						value: 77.49,
						currency: "USD",
					),
					deliveryTime: new ShippingDeliveryTime(
						handlingTime: new QuantitativeValue(
							unitCode: "DAY",
							minValue: 0,
							maxValue: 1
						),
						transitTime: new QuantitativeValue(
							unitCode: "DAY",
							minValue: 4,
							maxValue: 10
						)
					)
				),
				new OfferShippingDetails(
					shippingDestination: new DefinedRegion(
						addressCountry: "US",
						addressRegion: [ "AK" ]
					),
					doesNotShip: true,
				),
			]
		)
	]
);

$json = JsonLdGenerator::SchemaToJson(
	schema: $product
);