PHP code example of soez-smile / lullabot-amp
1. Go to this page and download the library: Download soez-smile/lullabot-amp 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/ */
soez-smile / lullabot-amp example snippets
use Lullabot\AMP\AMP;
use Lullabot\AMP\Validate\Scope;
// Create an AMP object
$amp = new AMP();
// Notice this is a HTML fragment, i.e. anything that can appear below <body>
$html =
'<p><a href="javascript:run();">Run</a></p>' . PHP_EOL .
'<p><a style="margin: 2px;" href="http://www.cnn.com" target="_parent">CNN</a></p>' . PHP_EOL .
'<p><a href="http://www.bbcnews.com" target="_blank">BBC</a></p>' . PHP_EOL .
'<p><INPUT type="submit" value="submit"></p>' . PHP_EOL .
'<p>This is a <div onmouseover="hello();">sample</div> paragraph</p>';
// Load up the HTML into the AMP object
// Note that we only support UTF-8 or ASCII string input and output. (UTF-8 is a superset of ASCII)
$amp->loadHtml($html);
// If you're feeding it a complete document use the following line instead
// $amp->loadHtml($html, ['scope' => Scope::HTML_SCOPE]);
// If you want some performance statistics (see https://github.com/Lullabot/amp-library/issues/24)
// $amp->loadHtml($html, ['add_stats_html_comment' => true]);
// Convert to AMP HTML and store output in a variable
$amp_html = $amp->convertToAmpHtml();
// Print AMP HTML
print($amp_html);
// Print validation issues and fixes made to HTML provided in the $html string
print($amp->warningsHumanText());
// warnings that have been passed through htmlspecialchars() function
// print($amp->warningsHumanHtml());
// You can do the above steps all over again without having to create a fresh object
// $amp->loadHtml($another_string)
// ...
// ...