PHP code example of zergius-eggstream / amp-converter

1. Go to this page and download the library: Download zergius-eggstream/amp-converter 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/ */

    

zergius-eggstream / amp-converter example snippets


use AmpConverter\AmpConverter;

$result = AmpConverter::createDefault()->convert(
    $renderedHtml,
    $siteRoot,
    canonicalUrl: 'https://example.com/the-page',
);
file_put_contents($outputPath, $result->html);
foreach ($result->warnings as $w) {
    error_log("amp-converter: $w");
}

namespace App\Renderer;

use AmpConverter\AmpConverter as Lib;

readonly class AmpConverter
{
    public function convert(string $renderedHtml, string $siteRoot): string
    {
        return Lib::createDefault()->convert($renderedHtml, $siteRoot)->html;
    }
}

use AmpConverter\AmpConverter;
use AmpConverter\Transformer\ImgToAmpImg;
use AmpConverter\PhpSnippets\MaskSnippets;
use AmpConverter\PhpSnippets\UnmaskSnippets;

$converter = new AmpConverter([
    new MaskSnippets(),
    new ImgToAmpImg(),
    new MyCustomTransformer(),
    new UnmaskSnippets(),
]);