### Install with Composer Source: https://github.com/masterminds/html5-php/wiki/Installation Add the masterminds/html5 package to your composer.json file to install using Composer. This is the recommended installation method. ```json { "require" : { "masterminds/html5": "dev-master" } } ``` -------------------------------- ### Install HTML5-PHP with Composer Source: https://github.com/masterminds/html5-php/blob/master/README.md Install the HTML5-PHP library using Composer by adding it to your composer.json file or by using the require command. ```json { "require" : { "masterminds/html5": "^2.0" }, } ``` ```bash composer require masterminds/html5 ``` -------------------------------- ### HTML Document with Processor Instruction Source: https://github.com/masterminds/html5-php/wiki/Processor-Instructions Example of an HTML document containing a processor instruction. ```html ``` -------------------------------- ### Setup Email Subscriber Widget Source: https://github.com/masterminds/html5-php/blob/master/test/benchmark/example.html Configures the RequireJS module for the email subscriber widget and sets up its options. Use this to initialize the subscriber form on your page. ```javascript require.config({ paths: { 'nytint/email-subscriber' : 'https://int.nyt.com/applications/email-subscriber/client' } }); require(['foundation/main'], function() { require(['nytint/email-subscriber'], function(Subscriber) { Subscriber.setup({ containerId: 'smarter-living-form-only', productCode: 'SL', elementToHideOnSubscribe: '.nythp-smarter-living-formonly-email-promo', text: {unregisteredButton: 'Sign Up', unregisteredPlaceholder: 'Get Smarter Living by email', registeredButton: 'Sign Up', alreadySubscribedMessage: 'You’re already subscribed.', thanksMessage: 'You’ve signed up as %email%', emailPreferencesLinkText: 'Update your mail preferences »', errorMessage: 'Error submitting, please try again.', registeredWelcome: 'Get Smarter Living by email'} }); setTimeout(function(){ var widget = document.getElementById('smarter-living-form-only'); var container = widget.getElementsByTagName('div')[0]; var form = widget.getElementsByTagName('form')[0]; var status = container.getAttribute('data-status'); var notify = widget.getElementsByClassName('notify-email')[0]; if(notify !== undefined){ var origtext = notify.getAttribute('placeholder'); var newtext = 'Please enter your email address'; var button = container.getElementsByTagName('button')[0]; widget.setAttribute('class','clearfix'); notify.addEventListener('mouseover',function(){ notify.setAttribute('placeholder',newtext); }); notify.addEventListener('mouseout',function(){ notify.setAttribute('placeholder',origtext); }); notify.addEventListener('focus',function(){ notify.setAttribute('placeholder',''); }); } if(form !== undefined){ notify.addEventListener('keyup',function(){ form.setAttribute('class','dirtyform'); }); container.setAttribute('class','not-signedin'); } else { container.setAttribute('class','signedin'); } },2000); }); }); ``` -------------------------------- ### Example HTML5 Parser Error Output Source: https://github.com/masterminds/html5-php/wiki/Parser-Errors This is an example of the output format for parser errors when no DOCTYPE is specified. ```text Array ( [0] => Line 0, Col 0: No DOCTYPE specified. ) ``` -------------------------------- ### Setup Email Subscriber Widget (Europe Edition) Source: https://github.com/masterminds/html5-php/blob/master/test/benchmark/example.html Configures and sets up an email subscriber widget for the Europe Edition. It dynamically adjusts UI elements and event listeners based on user interaction and subscription status. ```javascript require.config({ paths: { 'nytint/email-subscriber' : 'https://int.nyt.com/applications/email-subscriber/client' } }); require(['foundation/main'], function() { require(['nytint/email-subscriber'], function(Subscriber) { Subscriber.setup({ containerId: 'morning-briefing-widget-au', productCode: 'MBAU', /* elementToHideOnSubscribe: '.nythp-morning-briefing-email-promo', */ text: {unregisteredButton: 'Sign Up', unregisteredPlaceholder: 'Get the Morning Briefing by email.', registeredButton: 'Sign Up', alreadySubscribedMessage: 'You’re already subscribed.', thanksMessage: 'You’ve signed up as %email%', emailPreferencesLinkText: 'Update your mail preferences »', errorMessage: 'Error submitting, please try again.', registeredWelcome: 'Get the Morning Briefing by email.'} }); setTimeout(function(){ var widget = document.getElementById('morning-briefing-widget-au'); var container = widget.getElementsByTagName('div')[0]; var form = widget.getElementsByTagName('form')[0]; var status = container.getAttribute('data-status'); var notify = widget.getElementsByClassName('notify-email')[0]; if(notify !== undefined){ var origtext = notify.getAttribute('placeholder'); var newtext = 'Please enter your email address'; var button = container.getElementsByTagName('button')[0]; widget.setAttribute('class','clearfix'); notify.addEventListener('mouseover',function(){ notify.setAttribute('placeholder',newtext); }); notify.addEventListener('mouseout',function(){ notify.setAttribute('placeholder',origtext); }); notify.addEventListener('focus',function(){ notify.setAttribute('placeholder',''); }); } if(form !== undefined){ notify.addEventListener('keyup',function(){ form.setAttribute('class','dirtyform'); }); container.setAttribute('class','not-signedin'); } else { container.setAttribute('class','signedin'); } },2000); }); }); ``` -------------------------------- ### Setup Email Subscriber Widget (Asia Edition) Source: https://github.com/masterminds/html5-php/blob/master/test/benchmark/example.html Configures and sets up an email subscriber widget for the Asia Edition. It dynamically adjusts UI elements and event listeners based on user interaction and subscription status. ```javascript require.config({ paths: { 'nytint/email-subscriber' : 'https://int.nyt.com/applications/email-subscriber/client' } }); require(['foundation/main'], function() { require(['nytint/email-subscriber'], function(Subscriber) { Subscriber.setup({ containerId: 'morning-briefing-widget-as', productCode: 'MBAE', /* elementToHideOnSubscribe: '.nythp-morning-briefing-email-promo', */ text: {unregisteredButton: 'Sign Up', unregisteredPlaceholder: 'Get the Morning Briefing by email.', registeredButton: 'Sign Up', alreadySubscribedMessage: 'You’re already subscribed.', thanksMessage: 'You’ve signed up as %email%', emailPreferencesLinkText: 'Update your mail preferences »', errorMessage: 'Error submitting, please try again.', registeredWelcome: 'Get the Morning Briefing by email.'} }); setTimeout(function(){ var widget = document.getElementById('morning-briefing-widget-as'); var container = widget.getElementsByTagName('div')[0]; var form = widget.getElementsByTagName('form')[0]; var status = container.getAttribute('data-status'); var notify = widget.getElementsByClassName('notify-email')[0]; if(notify !== undefined){ var origtext = notify.getAttribute('placeholder'); var newtext = 'Please enter your email address'; var button = container.getElementsByTagName('button')[0]; widget.setAttribute('class','clearfix'); notify.addEventListener('mouseover',function(){ notify.setAttribute('placeholder',newtext); }); notify.addEventListener('mouseout',function(){ notify.setAttribute('placeholder',origtext); }); notify.addEventListener('focus',function(){ notify.setAttribute('placeholder',''); }); } if(form !== undefined){ notify.addEventListener('keyup',function(){ form.setAttribute('class','dirtyform'); }); container.setAttribute('class','not-signedin'); } else { container.setAttribute('class','signedin'); } },2000); }); }); ``` -------------------------------- ### Load HTML and Get Parser Errors in PHP Source: https://github.com/masterminds/html5-php/wiki/Parser-Errors Use this snippet to load an HTML string and retrieve any parser errors encountered. Ensure the HTML5 class is imported. ```php $html = <<< 'HERE'
This is a test of the HTML5 parser.
HERE; $html5 = new HTML5(); $dom = $html5->loadHTML($html); print_r($html5->getErrors()); ``` -------------------------------- ### JavaScript Initialization and User Data Handling Source: https://github.com/masterminds/html5-php/blob/master/test/benchmark/example.html Initializes a signup promo view, handles user data readiness, and switches promotional text based on A/B test variants. It also tracks impressions and clicks. ```javascript require(['foundation/main'], function(main) { require(['jquery/nyt', 'underscore/nyt', 'foundation/models/user-data', 'foundation/tracking/tracking-mixin', 'foundation/views/page-manager', 'foundation/hosts'], function ($, _, userData, trackingMixin, pageManager, hosts) { var signupPromo = { taglines: { 'promo1': 'Journalism that matters.This is a test of the HTML5 parser.