rehike / spfphp
A PHP library for generating SPF.js-compatible page fragments.
Requires
- php: >=7.0.0
- yukiscoffee/simple_html_dom: 4.8.9
README
SpfPhp was mostly a Rehike-specific hack that should have been worked around a long time ago. For more efficient performance, this project will be deprecated and Rehike will move away from it in the future.
If you are a third-party user of the SpfPhp library, then feel free to make a fork and continue maintaining it.
SpfPhp
A PHP library that parses and transforms HTML into the JSON required by YouTube's SPF.js.
Installation
The recommended installation method is via Composer:
composer require rehike/spfphp
After installation, use the library like such:
require "vendor/autoload.php"; // Include Composer packages use SpfPhp\SpfPhp;
Get started
SpfPhp is designed with the most portability in mind. With that, it does not require the use of or integrate with any particular templating engine.
To use this with any templating engine, or just PHP alone, simply wrap all output with these following functions:
<?php SpfPhp::beginCapture(); ?> <html> <head> <title>Example</title> </head> <body> <div id="content" x-spfphp-capture>Hello world!</div> </body> </html> <?php // Then tell SpfPhp we need it SpfPhp::autoRender();
Click here for further documentation
See an example project
Acknowledgements
SpfPhp makes use of the following open-source software:
- voku/simple_html_dom
- YukisCoffee's fork is used instead, in order to patch a bug with the upstream library.