将 HTML 转换为 AMP HTML,并报告 HTML 是否符合 AMP HTML 规范
An open source PHP library and console utility to convert HTML to AMP HTML and report HTML compliance with the AMP HTML specification.
The AMP PHP Library is an open source and pure PHP Library that:
style attribute within `` tagLine 9:
Line 10:
at line 3 ACTION TAKEN: img tag was converted to the amp-img tag.
at line 7 ACTION TAKEN: iframe tag was converted to the amp-iframe tag.
FAIL
on line 1
on line 2
on line 5
paragraph ';
// 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) // ... // ...
### Tips
- Its probably not a good idea to run the library on your HTML dynamically on _every_ page view. You should try caching the results of `$amp->convertToAmpHtml()` once the library has run. If you're using the library from a CMS then you should consider using the caching facilities provided by the CMS.
### Caveats and Known issues
- We only support UTF-8 string input and output from the library. If you're using ASCII, then you don't need to worry as UTF-8 is a superset of ASCII. If you're using another encoding like Latin-1 (etc.) you'll need to convert to UTF-8 strings before you use this library
- If you have ``s with `https` urls _and_ they don't have height/width attributes _and_ you are using PHP 5.6 or higher _and_ you have not listed any certificate authorities (`cafile`) in your `php.ini` file _then_ the library may have problems converting these to ``. This is because of http://php.net/manual/en/migration56.openssl.php . That link also has a work around.
- If your `` pins are appearing "chopped off" (after pinterest embed code conversion) try the workaround [here](https://github.com/Lullabot/amp-library/issues/46#issuecomment-230424580)
### Useful Links
- [Composer homepage](https://packagist.org/packages/lullabot/amp) for the AMP PHP Library on [Packagist](https://packagist.org/), the PHP package repository
- AMP Project [Homepage](https://www.ampproject.org/)
- AMP Project [code repository](https://github.com/ampproject/amphtml) on Github
- [AMP HTML JavaScript validator subtree](https://github.com/ampproject/amphtml/tree/main/validator) on Github within the AMP Project code repository
- [Technical Specification](https://github.com/ampproject/amphtml/blob/main/validator/validator-main.protoascii) of AMP HTML in [Protocol Buffers](https://developers.google.com/protocol-buffers/) ASCII message format. See [here](https://github.com/ampproject/amphtml/blob/main/validator/validator.proto) for the Schema definition of the technical specification
### Useful Links for amp-library developers
- [Notes](https://github.com/Lullabot/amp-library/blob/main/src/Spec/README.md) on the contents of the `src/Spec` folder
- [Notes](https://github.com/Lullabot/amp-library/blob/main/src/Validate/README.md) on the contents of the `src/Validate` folder
You can ignore these links if you simply plan to _use_ this library and not develop for it
### Third-party libraries
- Symfony:
- [takeit/amp-html-bundle](https://github.com/takeit/AmpHtmlBundle)
- Drupal:
- [Drupal AMP Module](https://www.drupal.org/project/amp)
### Sponsored by
- Google for creating the AMP Project and sponsoring development
- Lullabot for development of the module, theme, and library to work with the specifications暂无开放 Issues,或尚未同步最近议题。