0
<?php
// Your code here!
$dom = new DOMDocument();
$html = '<div id="tmp-wrapper">Test Test
<audio class="player mejs-custom" src="$[*audio-file_example_MP3_700KB.mp3*]" type="audio/mp3" playLimit="0" allowPause="False" allowSeek="False">
</audio></div>';
try {
$dom->loadHTML(
                mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'),
                LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD
            );
}catch (\Exception $ex) {
            /*
             * DOM parser has problem processing HTML content,
             * return input as it is.
             */
            echo 'Failed to parse DOM document for accessibility: ' . $ex->getMessage();
            return $html;
        }
?>

I am getting the error for audio tag. is there any way we can prevent exception for audio?

PHP Warning: DOMDocument::loadHTML(): Tag audio invalid in Entity, line: 2 in /workspace/Main.php on line 10

  • 1
    ...and what exactly is the exception message? It really helps to know what the problem is, if anyone is going to try and solve it! See also [ask] and the [tour] please, as you are new to Stackoverflow. – ADyson Feb 21 '23 at 12:51
  • PHP Warning: DOMDocument::loadHTML(): Tag audio invalid in Entity, line: 2 in /workspace/Main.php on line 10 This is exception message I am getting – Bina Pithadiya Feb 21 '23 at 12:52
  • That's a warning, not an exception. Your code is not actually crashing. – ADyson Feb 21 '23 at 12:55
  • 2
    `HTML-ENTITIES` is not an encoding. What are you trying to do with that – user3783243 Feb 21 '23 at 12:55
  • See this comment: https://stackoverflow.com/questions/6090667/php-domdocument-errors-warnings-on-html5-tags#comment101538693_6090728 . Probably what you're doing is ok, but it's still firing a warning for some reason. Did you google this message up till now? And is anything else you've tried to do with that tag after this code actually not working? – ADyson Feb 21 '23 at 12:56
  • @user3783243, I am sending this HTML for translation to another API so getting this warning before that – Bina Pithadiya Feb 21 '23 at 13:00
  • @ADyson, yes I have already tried that but still getting warning – Bina Pithadiya Feb 21 '23 at 13:01
  • Tried what, exactly? I didn't suggest to try anything, I just asked you to note the comment. – ADyson Feb 21 '23 at 13:02
  • You can suppress that error using `libxml_use_internal_errors(true);`, if you want. – CBroe Feb 21 '23 at 13:05

0 Answers0