{"id":55271,"date":"2022-03-31T03:01:57","date_gmt":"2022-03-30T17:01:57","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=55271"},"modified":"2022-03-30T15:42:46","modified_gmt":"2022-03-30T05:42:46","slug":"html-online-validation-via-error-array-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-error-array-tutorial\/","title":{"rendered":"HTML Online Validation via Error Array Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"HTML Online Validation via Error Array Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example_errors.jpg\" title=\"HTML Online Validation via Error Array Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">HTML Online Validation via Error Array Tutorial<\/p><\/div>\n<p>Today&#8217;s job is to sharpen up the DOMDocument Online HTML Validation error reporting, onto yesterday&#8217;s <a title='HTML Online Validation via PHP Rendering Tutorial' href='#htmlovphprt'>HTML Online Validation via PHP Rendering Tutorial<\/a> by &#8230;<\/p>\n<ul>\n<li>organizing the error messages to appear in a right hand column of a two column table, rather than up the top before any HTML &#8230; and &#8230;<\/li>\n<li>via <font color=blue>new error processing code<\/font> &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  <font color=blue><a target=_blank title='PHP libxml_use_internal_errors function information' href='https:\/\/www.php.net\/manual\/en\/function.libxml-use-internal-errors.php'>libxml_use_internal_errors<\/a>(true);<\/font><br \/>\n  $doc = new DOMDocument();<br \/>\n  <font color=blue>$doc-&gt;validateOnParse = true;<\/font><br \/>\n  $doc-&gt;loadHTML($htmlin);<br \/>\n<br \/> <br \/>\n  <font color=blue>$betterwithin=str_replace(\"\\n\",\"  &lt;BR&gt;\",$htmlin);<br \/>\n  $within=str_replace(\"\\n\",\"  &lt;BR&gt;\",str_replace('&gt;','~',str_replace('&lt;','`',$htmlin)));<br \/>\n  $bws=explode(\"&lt;BR&gt;\", $betterwithin);<br \/>\n  $betterbws=explode(\"&lt;BR&gt;\", $betterwithin);<br \/>\n<br \/> <br \/>\n  foreach (libxml_get_errors() as $error) { \/\/ thanks to <a target=_blank title='https:\/\/www.php.net\/manual\/en\/function.libxml-get-errors.php' href='https:\/\/www.php.net\/manual\/en\/function.libxml-get-errors.php'>https:\/\/www.php.net\/manual\/en\/function.libxml-get-errors.php<\/a><br \/>\n    \/\/ handle errors here<br \/>\n    if ($emore == '') { $emore.='&lt;br&gt;&lt;br&gt;&lt;table border=2 cellpadding=5 cellspacing=5 style=background-color:#ffffe0;&gt;&lt;tr&gt;&lt;td&gt;' . $within . '&lt;\/td&gt;&lt;td&gt;'; }<br \/>\n    switch ($error-&gt;level) {<br \/>\n        case LIBXML_ERR_WARNING:<br \/>\n            $emore .= \"DOMDocument::loadHTML(); Warning $error-&gt;code: \";<br \/>\n            break;<br \/>\n         case LIBXML_ERR_ERROR:<br \/>\n            $emore .= \"DOMDocument::loadHTML(); Error $error-&gt;code: \";<br \/>\n            break;<br \/>\n        case LIBXML_ERR_FATAL:<br \/>\n            $emore .= \"DOMDocument::loadHTML(); Fatal Error $error-&gt;code: \";<br \/>\n            break;<br \/>\n    }<br \/>\n    $emore.=$error-&gt;message . ' at line ' . $error-&gt;line . '  &lt;SUB&gt;' . $error-&gt;line . '&lt;\/SUB&gt;, column ' . $error-&gt;column . ' &lt;SUP&gt;&amp;#10067;&lt;\/SUP&gt;&lt;br&gt;';<br \/>\n    if ($error-&gt;column == 0) {<br \/>\n      $betterbws[-1 + $error-&gt;line]='&lt;SUB&gt;' . $error-&gt;line . '&lt;\/SUB&gt;&lt;SUP&gt;&amp;#10067;&lt;\/SUP&gt;' . $betterbws[-1 + $error-&gt;line];<br \/>\n    } else {<br \/>\n      $betterbws[-1 + $error-&gt;line]=substr($betterbws[-1 + $error-&gt;line],0,$error-&gt;column) . '&lt;SUB&gt;' . $error-&gt;line . '&lt;\/SUB&gt;&lt;SUP&gt;&amp;#10067;&lt;\/SUP&gt;' . substr($betterbws[-1 + $error-&gt;line],$error-&gt;column);<br \/>\n    }<br \/>\n    $betterwithin=str_replace($bws[-1 + $error-&gt;line], $betterbws[-1 + $error-&gt;line], $betterwithin);<br \/>\n  }<br \/>\n  libxml_clear_errors();<br \/>\n  if ($emore != '') {<br \/>\n    $emore=str_replace($within, str_replace('&lt;\/SUP&gt;','&lt;\/sup&gt;',str_replace('&lt;SUP&gt;','&lt;sup&gt;',str_replace('&lt;\/SUB&gt;','&lt;\/sub&gt;',str_replace('&lt;SUB&gt;','&lt;sub&gt;',str_replace('&lt;BR&gt;','&lt;br&gt;',str_replace('&gt;','&gt;',str_replace('&lt;','&lt;',$betterwithin))))))), $emore) . '&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;&lt;br&gt;';<br \/>\n  }<\/font><br \/>\n  $tec='No tidy module detected.'<font color=blue> . $emore<\/font>;<br \/>\n<\/code><br \/>\n?&gt;<br \/>\n &#8230; be able to add to the precision of the HTML validation linking that right hand column entries with left hand HTML content context via the use of &lt;sub&gt;[line number]&lt;\/sub&gt; and &lt;sup&gt;&amp;10067;&lt;\/sup&gt; (&#10067;) &#8220;linkers&#8221;\n<\/li>\n<\/ul>\n<p> &#8230; with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php---GETME\" title=\"tidy_example.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php---GETME\" title=\"tidy_example.php\">tidy_example.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\" title=\"Click picture\">proof of concept PHP online HTML validator web application<\/a> you can try <a href='#myifdd' title='Iframe usage'>here also<\/a>, the mobile platform versions of which only allow the DOMDocument methodology be used.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-error-array-tutorial\/'>HTML Online Validation via Error Array Tutorial<\/a>.<\/p-->\n<hr>\n<p id='htmlovphprt'>Previous relevant <a target=_blank title='HTML Online Validation via PHP Rendering Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-php-rendering-tutorial\/'>HTML Online Validation via PHP Rendering Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"HTML Online Validation via PHP Rendering Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example_plus.jpg\" title=\"HTML Online Validation via PHP Rendering Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">HTML Online Validation via PHP Rendering Tutorial<\/p><\/div>\n<p>Onto yesterday&#8217;s <a title='HTML Online Validation via PHP DOMDocument Tutorial' href='#htmlovphpdomdt'>HTML Online Validation via PHP DOMDocument Tutorial<\/a>, today, we tackle numerous improvements and fixes to our Online HTML Validator (PHP) web application as per &#8230;<\/p>\n<ul>\n<li>add PHP <i>tidy<\/i> module parsing results in <font color=blue>HTML report<\/font> &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n    $tec='' . tidy_error_count($tidy) . ' errors<font color=blue>&lt;br&gt;&lt;pre onclick=woit(this); id=tidyout title=\"PHP tidy parses HTML to look like below and click here to show web browser rendering\" style=background-color:pink;&gt;' . str_replace('&gt;','&gt;',str_replace('&lt;','&lt;',tidy_get_output($tidy))) . '&lt;\/pre&gt;<\/font>';<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<li>add onclick=woit(this); logic to HTML content elements to show how the web browser would <i>render<\/i> such HTML &#8230;<br \/>\n&lt;?php echo &#8221;<br \/>\n<code><br \/>\n  var wo=null;<br \/>\n  var ofc=false;<br \/>\n  var lasttitle=' ';<br \/>\n  var lastcont='';<br \/>\n<br \/> <br \/>\n  function woit(ine) {<br \/>\n    var asttitle='';<br \/>\n    var astcont='';<br \/>\n    var rectis=ine.getBoundingClientRect();<br \/>\n    if (wo) { wo.close(); wo=null; }<br \/>\n    if (('' + ine.type) == 'textarea' && ofc) {<br \/>\n      ofc=true;<br \/>\n    } else {<br \/>\n    if (('' + ine.outerHTML).indexOf('&lt;\/h4&gt;') != -1) {<br \/>\n      if (('' + ine.getAttribute('data-render')) != '') {<br \/>\n      var prefx='';<br \/>\n      var sufx='';<br \/>\n      if (('' + ine.getAttribute('data-render')).replace(\/\\&gt\\;\/g,'&gt;').replace(\/\\&lt\\;\/g,'&lt;').indexOf('&lt;\/body&gt;') == -1) {<br \/>\n      prefx='&lt;html&gt;&lt;body&gt;';<br \/>\n      sufx='&lt;\/body&gt;&lt;\/html&gt;';<br \/>\n      } else if (('' + ine.getAttribute('data-render')).replace(\/\\&gt\\;\/g,'&gt;').replace(\/\\&lt\\;\/g,'&lt;').indexOf('&lt;\/html&gt;') == -1) {<br \/>\n      prefx='&lt;html&gt;';<br \/>\n      sufx='&lt;\/html&gt;';<br \/>\n      }<br \/>\n      astcont=prefx + ('' + ine.getAttribute('data-render')).replace(\/\\&gt\\;\/g,'&gt;').replace(\/\\&lt\\;\/g,'&lt;').replace(\/\\&\\#10004\\;\\ \/g,'').replace(\/\\&\\#10060\\;\\ \/g,'') + sufx;<br \/>\n    if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n      wo=window.open('','_blank');<br \/>\n    } else {<br \/>\n      wo=window.open('','_blank','left=' + rectis.left + ',top=' + rectis.top + ',width=' + rectis.width + ',height=' + rectis.height);<br \/>\n    }<br \/>\n      wo.document.write(astcont);<br \/>\n      wo.document.title='PHP DOMDocument parsing passed onto web browser rendering';<br \/>\n      lastcont=astcont;<br \/>\n      } else if (ine.innerHTML.indexOf('&lt;br&gt;' + String.fromCharCode(10) + '&lt;br&gt;' + String.fromCharCode(10) + '&lt;br&gt;' + String.fromCharCode(10)) != -1) {<br \/>\n      astcont=ine.innerHTML.split('&lt;br&gt;' + String.fromCharCode(10) + '&lt;br&gt;' + String.fromCharCode(10) + '&lt;br&gt;' + String.fromCharCode(10))[1].replace(\/\\&gt\\;\/g,'&gt;').replace(\/\\&lt\\;\/g,'&lt;').replace(\/\\&\\#10004\\;\\ \/g,'').replace(\/\\&\\#10060\\;\\ \/g,'').replace(\/\\&\\#10067\\;\\ \/g,'');<br \/>\n      asttitle='PHP DOMDocument parsing passed onto web browser rendering';<br \/>\n      if (asttitle != lasttitle || astcont != lastcont) {<br \/>\n    if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n      wo=window.open('','_blank');<br \/>\n    } else {<br \/>\n      wo=window.open('','_blank','left=' + rectis.left + ',top=' + rectis.top + ',width=' + rectis.width + ',height=' + rectis.height);<br \/>\n    }<br \/>\n      wo.document.write(astcont);<br \/>\n      lastcont=astcont;<br \/>\n      }<br \/>\n      } else {<br \/>\n      astcont=ine.innerHTML.replace(\/\\&gt\\;\/g,'&gt;').replace(\/\\&lt\\;\/g,'&lt;').replace(\/\\&\\#10004\\;\\ \/g,'').replace(\/\\&\\#10060\\;\\ \/g,'').replace(\/\\&\\#10067\\;\\ \/g,'').replace(\/^\\ \\.\\.\\.\\ \/g,'');<br \/>\n      asttitle='PHP DOMDocument parsing passed onto web browser rendering';<br \/>\n      if (asttitle != lasttitle || astcont != lastcont) {<br \/>\n    if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n      wo=window.open('','_blank');<br \/>\n    } else {<br \/>\n      wo=window.open('','_blank','left=' + rectis.left + ',top=' + rectis.top + ',width=' + rectis.width + ',height=' + rectis.height);<br \/>\n    }<br \/>\n      wo.document.write(astcont);<br \/>\n      lastcont=astcont;<br \/>\n      }<br \/>\n      wo.document.title='PHP DOMDocument parsing passed onto web browser rendering';<br \/>\n      lasttitle='PHP DOMDocument parsing passed onto web browser rendering';<br \/>\n      }<br \/>\n    } else if (('' + ine.type) != 'textarea') {<br \/>\n      astcont=ine.outerHTML.split('&lt;\/pre&gt;')[0].split('&gt;')[1].replace(\/\\&gt\\;\/g,'&gt;').replace(\/\\&lt\\;\/g,'&lt;');<br \/>\n      asttitle='PHP tidy module parsing passed onto web browser rendering';<br \/>\n      if (asttitle != lasttitle || astcont != lastcont) {<br \/>\n    if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n      wo=window.open('','_blank');<br \/>\n    } else {<br \/>\n      wo=window.open('','_blank','left=' + rectis.left + ',top=' + rectis.top + ',width=' + rectis.width + ',height=' + rectis.height);<br \/>\n    }<br \/>\n      wo.document.write(astcont);<br \/>\n      lastcont=astcont;<br \/>\n      wo.document.title='PHP tidy module parsing passed onto web browser rendering';<br \/>\n      lasttitle='PHP tidy module parsing passed onto web browser rendering';<br \/>\n      }<br \/>\n    } else {<br \/>\n      astcont=ine.value;<br \/>\n      if (document.URL.indexOf('localhost') != -1) {<br \/>\n      asttitle='Your proposed HTML passed onto web browser rendering';<br \/>\n      } else {<br \/>\n      asttitle='Your proposed HTML passed onto web browser rendering';<br \/>\n      }<br \/>\n      if (asttitle != lasttitle || astcont != lastcont) {<br \/>\n    if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n      wo=window.open('','_blank');<br \/>\n    } else {<br \/>\n      wo=window.open('','_blank','left=' + rectis.left + ',top=' + rectis.top + ',width=' + rectis.width + ',height=' + rectis.height);<br \/>\n    }<br \/>\n      wo.document.write(astcont);<br \/>\n      lastcont=astcont;<br \/>\n      if (document.URL.indexOf('localhost') != -1) {<br \/>\n      wo.document.title='Your proposed HTML passed onto web browser rendering';<br \/>\n      lasttitle='Your proposed HTML passed onto web browser rendering';<br \/>\n      } else {<br \/>\n      wo.document.title='Your proposed HTML passed onto web browser rendering';<br \/>\n      lasttitle='Your proposed HTML passed onto web browser rendering';<br \/>\n      }<br \/>\n      }<br \/>\n    }<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><br \/>\n&#8220;; ?&gt;\n<\/li>\n<li>deal with user HTML that contains the <i>+<\/i> character (which PHP uses for space encoding, as distinct from Javascript encodeURIComponent&#8217;s use of %20 for space encoding) via new <i>form<\/i> <i>onsubmit=&#8217;return butplus(this);&#8217;<\/i> logic as per &#8230;<br \/>\n&lt;?php echo &#8221;<br \/>\n<code><br \/>\n  function butplus(thisf) {<br \/>\n    var idof=thisf.innerHTML.split(' id=\\\"')[1].split('\\\"')[0];<br \/>\n    if (document.getElementById(idof).value.indexOf('+') != -1) {<br \/>\n      if (('' + thisf.method).toLowerCase() == 'get') {<br \/>\n        location.href=thisf.action + '?' + idof + '=' + encodeURIComponent(document.getElementById(idof).value);<br \/>\n        return false;<br \/>\n      } else if (encodeURIComponent(document.getElementById(idof).value).length &lt;= 800) {<br \/>\n        thisf.method='GET';<br \/>\n        location.href=thisf.action + '?' + idof + '=' + encodeURIComponent(document.getElementById(idof).value);<br \/>\n        return false;<br \/>\n      } else {<br \/>\n        document.getElementById(idof).value=document.getElementById(idof).value.replace(\/\\+\/g,encodeURIComponent('+'));<br \/>\n      }<br \/>\n    }<br \/>\n    return true;<br \/>\n  }<br \/>\n<\/code><br \/>\n&#8220;; ?&gt;\n<\/li>\n<li>add a &#10067; ( <font color=blue>&amp;#10067;<\/font> ) status to DOMDocument parsing logic where the current interim okayed element&#8217;s outerHTML is contained wholly in the previous erroneous parent element &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\nfunction nodeContent($n, $outer=false) { \/\/ thanks to https:\/\/stackoverflow.com\/questions\/5404941\/how-to-return-outer-html-of-domdocument<br \/>\n    global $ioff, $origh<font color=blue>, $lasth<\/font>;<br \/>\n    $d = new DOMDocument();<br \/>\n    $b = $d-&gt;importNode($n-&gt;cloneNode(true),true);<br \/>\n    $d-&gt;appendChild($b);<br \/>\n    $h = $d-&gt;saveHTML();<br \/>\n    \/\/ remove outter tags<br \/>\n    if (!$outer) {<br \/>\n     $h = substr($h,strpos($h,'&gt;')+1,-(strlen($n-&gt;nodeName)+4));<br \/>\n    } else {<br \/>\n     if ($ioff == -2 && strpos(strtolower($h), '&lt;html') !== false) {  return '';   }<br \/>\n     if ($ioff &lt;= -1 && strpos(strtolower($h), '&lt;body') !== false) {  return '';   }<br \/>\n    }<br \/>\n    if (stripos( str_replace('&nbsp;','',str_replace(' ','',str_replace(\"\\n\",'',str_replace(\"\\r\",'',str_replace(\"\\r\\n\",'',str_replace(\"'\",'',str_replace('\"','',$origh))))))),str_replace('&nbsp;','',str_replace(' ','',str_replace(\"\\n\",'',str_replace(\"\\r\",'',str_replace(\"\\r\\n\",'',str_replace(\"'\",'',str_replace('\"','',('' . $h))))))))  ) !== false) {<br \/>\n      <font color=blue>if (strpos(str_replace('&gt;','&gt;',str_replace('&lt;','&lt;',str_replace('&nbsp;','',str_replace(' ','',str_replace(\"\\n\",'',str_replace(\"\\r\",'',str_replace(\"\\r\\n\",'',str_replace(\"'\",'',str_replace('\"','',('' . $lasth)))))))))), str_replace('&gt;','&gt;',str_replace('&lt;','&lt;',str_replace('&nbsp;','',str_replace(' ','',str_replace(\"\\n\",'',str_replace(\"\\r\",'',str_replace(\"\\r\\n\",'',str_replace(\"'\",'',str_replace('\"','',('' . $h))))))))))) !== false) {<br \/>\n        return '&amp;#10067; ' . $h;<br \/>\n      }<br \/>\n      $lasth=\"\";<br \/>\n      return '&amp;#10004; ' . $h;<\/font><br \/>\n    } else if (1 == 1) {<br \/>\n      <font color=blue>if (stripos($h, '&lt;\/body&gt;') === false) {<br \/>\n      $lasth='&amp;#10060; ' . $h;<br \/>\n      return $lasth;<br \/>\n      } else {<br \/>\n      $lasth=\"\";<br \/>\n      return '&amp;#10060; ' . $h;<br \/>\n      }<\/font><br \/>\n    }<br \/>\n    return '' . $h;<br \/>\n}<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<li>add <font color=blue>more characters<\/font> to ignore with the <i>whitespace if<\/i> checking codeline &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n    if (stripos( str_replace('&nbsp;','',str_replace(' ','',<font color=blue>str_replace(\"\\n\",'',str_replace(\"\\r\",'',str_replace(\"\\r\\n\",'',str_replace(\"'\",'',<\/font>str_replace('\"','',$origh)<font color=blue>))))<\/font>)),str_replace('&nbsp;','',str_replace(' ','',str_replace(\"\\n\",'',<font color=blue>str_replace(\"\\r\",'',str_replace(\"\\r\\n\",'',str_replace(\"'\",'',<\/font>str_replace('\"','',('' . $h))<font color=blue>)))<\/font>)))  ) !== false) {<br \/>\n      \/\/ here if parsed outerHTML matches input outerHTML<br \/>\n    } else {<br \/>\n      \/\/ here if parsed outerHTML does not match input outerHTML<br \/>\n    }<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<li>do some CSS styling with the input type=submit buttons &#8230;<br \/>\n&lt;?php echo &#8221;<br \/>\n<code><br \/>\n&lt;style&gt; input[type=submit] {  width:40%; height:50px; border-radius:30px;  } &lt;\/style&gt;<br \/>\n<\/code><br \/>\n&#8220;; ?&gt;\n<\/li>\n<\/ul>\n<p>Again, <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php--GETME\" title=\"tidy_example.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php--GETME\" title=\"tidy_example.php\">tidy_example.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\" title=\"Click picture\">proof of concept PHP online HTML validator web application<\/a> you can try <a href='#myifdd' title='Iframe usage'>here also<\/a>, the mobile platform versions of which only allow the DOMDocument methodology be used.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-php-rendering-tutorial\/'>HTML Online Validation via PHP Rendering Tutorial<\/a>.<\/p-->\n<hr>\n<p id='htmlovphpdomdt'>Previous relevant <a target=_blank title='HTML Online Validation via PHP DOMDocument Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-php-domdocument-tutorial\/'>HTML Online Validation via PHP DOMDocument Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"HTML Online Validation via PHP DOMDocument Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example_dd.jpg\" title=\"HTML Online Validation via PHP DOMDocument Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">HTML Online Validation via PHP DOMDocument Tutorial<\/p><\/div>\n<p>The lack of platform functionality that yesterday&#8217;s <a title='HTML Online Validation via PHP Tidy Primer Tutorial' href='#htmlovphptpt'>HTML Online Validation via PHP Tidy Primer Tutorial<\/a> &#8220;Intranet feeling&#8221; <i>Online HTML Validator<\/i> web application was supported by, got us interested in exploring HTML validation via PHP <a target=_blank title=DOMDocument href='https:\/\/www.php.net\/manual\/en\/book.dom.php'>DOMDocument<\/a> methodologies.<\/p>\n<p>Yes, (serverside) PHP can work with (its version of) DOM (document object model) but not as well as (clientside) Javascript DOM can.  The validation of HTML at the serverside (PHP) stage does not take into account web page rendering, and so struggles to detect &#8220;well formed looking&#8221; HTML (but) with HTML tags that mean nothing.  But we can do some validation checking via &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\nfunction nodeContent($n, $outer=false) { \/\/ thanks to <a target=_blank title='https:\/\/stackoverflow.com\/questions\/5404941\/how-to-return-outer-html-of-domdocument' href='https:\/\/stackoverflow.com\/questions\/5404941\/how-to-return-outer-html-of-domdocument'>https:\/\/stackoverflow.com\/questions\/5404941\/how-to-return-outer-html-of-domdocument<\/a><br \/>\n    global $ioff, $origh;<br \/>\n    $d = new DOMDocument();<br \/>\n    $b = $d-&gt;importNode($n-&gt;cloneNode(true),true);<br \/>\n    $d-&gt;appendChild($b);<br \/>\n    $h = $d-&gt;saveHTML();<br \/>\n    \/\/ remove outter tags<br \/>\n    if (!$outer) {<br \/>\n     $h = substr($h,strpos($h,'&gt;')+1,-(strlen($n-&gt;nodeName)+4));<br \/>\n    } else {<br \/>\n     if ($ioff == -2 && strpos(strtolower($h), '&lt;html') !== false) {  return '';   }<br \/>\n     if ($ioff &lt;= -1 && strpos(strtolower($h), '&lt;body') !== false) {  return '';   }<br \/>\n    }<br \/>\n    if (stripos( str_replace(' ','',str_replace('\"','',$origh)),str_replace(' ','',str_replace(\"\\n\",'',str_replace('\"','',('' . $h))))  ) !== false) {<br \/>\n      return '&amp;#10004; ' . $h;<br \/>\n    } else if (1 == 1) {<br \/>\n      return '&amp;#10060; ' . $h;<br \/>\n    }<br \/>\n    return '' . $h;<br \/>\n}<br \/>\n<br \/>\n  $doc = new DOMDocument();<br \/>\n  $doc-&gt;loadHTML($htmlin);<br \/>\n  foreach ($doc-&gt;getElementsByTagName(\"*\") as $item) {<br \/>\n    $elecnt++;<br \/>\n    if ($rest == \"\") { $rest = \" ... \"; }<br \/>\n    $rest.=' &lt;br&gt;' . str_replace('&gt;','&gt;',str_replace('&lt;','&lt;',nodeContent($item, true)));<br \/>\n  }<br \/>\n  $twc='Number of elements detected is ' . ($ioff + $elecnt) . $rest;<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php-GETME\" title=\"tidy_example.php\">The changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php-GETME\" title=\"tidy_example.php\">tidy_example.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\" title=\"Click picture\">proof of concept PHP online HTML validator web application<\/a> you can try <a href='#myifdd' title='Iframe usage'>here also<\/a>, the mobile platform versions of which only allow the DOMDocument methodology be used.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-php-docdocument-tutorial\/'>HTML Online Validation via PHP DOMDocument Tutorial<\/a>.<\/p-->\n<hr>\n<p id='htmlovphptpt'>Previous relevant <a target=_blank title='HTML Online Validation via PHP Tidy Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-php-tidy-primer-tutorial\/'>HTML Online Validation via PHP Tidy Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"HTML Online Validation via PHP Tidy Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.jpg\" title=\"HTML Online Validation via PHP Tidy Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">HTML Online Validation via PHP Tidy Primer Tutorial<\/p><\/div>\n<p>In terms of your, perhaps <a target=_blank title='MAMP local Apache\/PHP\/MySql web server' href='http:\/\/mamp.info'>MAMP<\/a>, Apache\/PHP\/MySql local web server&#8217;s &#8220;low hanging fruit&#8221; for extending PHP functionality, what are the most straightforward PHP modules to look at?  We&#8217;d say &#8230;<\/p>\n<ol>\n<li>find your Apache\/PHP\/MySql local web server&#8217;s php.ini (or equivalent) &#8230;<\/li>\n<li>(text) edit this php.ini &#8230;<\/li>\n<li>find &#8220;extension=&#8221; section and see those that are commented out &#8230;<\/li>\n<li>these PHP modules will have been installed but held back from being activated &#8230;<\/li>\n<li>you can then uncomment these &#8230; <\/li>\n<li>File -&gt; Save the new version of php.ini &#8230; then &#8230;<\/li>\n<li>stop and start your Apache\/PHP\/MySql local web server<\/li>\n<\/ol>\n<p> &#8230; and we found on our macOS Apache\/PHP\/MySql local web server the chance to introduce into our thinking, the use of the PHP module called <a target=_blank title='PHP tidy module' href='https:\/\/www.php.net\/manual\/en\/book.tidy.php'>&#8220;tidy&#8221;<\/a>.  Doing the research and development on this lead us to believe we could develop an &#8220;online HTML validator&#8221; (for small amounts of HTML on the RJM Programming domain version, initially), with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php_GETME\" title=\"tidy_example.php\">tidy_example.php<\/a> (which we&#8217;d want you to download to the <a target=_blank title='Apache document root' href='https:\/\/www.google.com\/search?q=document+root+apache&#038;rlz=1C5CHFA_enAU973AU973&#038;oq=document+root+apache&#038;aqs=chrome..69i57j0i512l3j0i22i30l6.4801j0j4&#038;sourceid=chrome&#038;ie=UTF-8'>document root<\/a> folder of your, perhaps MAMP, Apache\/PHP\/MySql local web server, to enable our &#8220;Intranet&#8221; feeling modus operandi up at the RJM Programming public domain) <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\" title=\"Click picture\">proof of concept PHP online HTML validator web application<\/a> &#8230;<\/p>\n<p><iframe id=myifdd src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tidy_example.php\" style=\"width:100%;height:1600px;\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55244' onclick='var dv=document.getElementById(\"d55244\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/module\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55244' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55256' onclick='var dv=document.getElementById(\"d55256\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/dom\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55256' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55262' onclick='var dv=document.getElementById(\"d55262\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/rendering\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55262' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55271' onclick='var dv=document.getElementById(\"d55271\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/error\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55271' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s job is to sharpen up the DOMDocument Online HTML Validation error reporting, onto yesterday&#8217;s HTML Online Validation via PHP Rendering Tutorial by &#8230; organizing the error messages to appear in a right hand column of a two column table, &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/html-online-validation-via-error-array-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[85,103,2105,1750,354,356,360,1605,1929,394,576,744,802,861,932,997,1049,3625,3754,3753,1262,3945,1319,1357,1358],"class_list":["post-55271","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-apache","tag-array","tag-context","tag-document-root","tag-dom","tag-domdocument","tag-download","tag-encodeuricomponent","tag-error","tag-error-log","tag-html","tag-mamp","tag-module","tag-onclick","tag-php","tag-programming","tag-render","tag-rendering","tag-sub","tag-sup","tag-textarea","tag-tidy","tag-tutorial","tag-validate","tag-validation"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55271"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=55271"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55271\/revisions"}],"predecessor-version":[{"id":55277,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55271\/revisions\/55277"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=55271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=55271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=55271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}