简体   繁体   中英

convert PHP DOMDocument to be readable as html tags.

how do i convert elements that is created using DOMDocument to be readable as html?. if you run the code below the $appended will show the code like this = 在此处输入图片说明

but what i am aiming is for it to be converted to html tags and to look like this. 在此处输入图片说明

    <?php
        global $connection;
        $html = "<div id='suggested-video'> 
        <h2>Suggestion For you</h2>
        <ul>

        </ul>
        </div>";
        libxml_use_internal_errors(true);
        $doc = new DOMDocument(); 
        $doc->loadHTML($html);

        $sexy = 'sexy';
        $limit = 12;
        $isi = 1;
        $arrayz = array();
        $arrayz2 = array();
        $query = "SELECT `videoname`,`username`,`videourl`,`uploaddate`,`duration`,`views`,`tags`,`videoimage` FROM `videolist` WHERE `tags` = ? ";
        $stmt = $connection->prepare($query);
        $stmt->bind_param('s',$sexy);
        //$stmt->bindValue(":limitz",4,PDO::PARAM_INT);
        //$stmt->bindValue(":isi",1,PDO::PARAM_INT);
        $stmt->execute();
        $stmt->store_result();
        if($stmt->num_rows > 0){

            $stmt->bind_result($videoname,$username,$videourl,$uploaddate,$duration,$views,$tags,$videoimage);
            while ($stmt->fetch()) {
                $descBox = $doc->getElementById('suggested-video');

                //create the element to append to #element1
                $appended = $doc->createElement('li', "
                        <a href='video.php?watch=$videourl'>
                            <li>
                                <div class='leftside'>
                                    <img src='' width='100%' height='100%' style='background-color: blue;' >                    
                                </div>

                                <div class='rightside'>
                                    <h4>$videoname</h4>
                                    <p>$username</p>
                                    <p>$views views</p>
                                    <p>$duration</p>                    
                                </div>

                            </li>
                        </a>

                ");

                //actually append the element
                $descBox->appendChild($appended);

            }
            echo $doc->saveHTML();
        }
    ?>

尝试使用html_entity_decode

echo html_entity_decode($doc->saveHTML());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM