php
  • html
  • domdocument
  • 2017-01-08 8 views 0 likes 
    0

    DOMDocumentを使用して作成された要素をhtmlとして読みやすいように変換するにはどうすればよいですか。下のコードを実行すると、$ addedは次のようなコードを表示します。= enter image description herePHP DOMDocumentをHTMLタグとして読み込み可能に変換します。

    これはhtmlタグに変換され、このように表示されることを目的としています。 enter image description here

    <?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(); 
         } 
        ?> 
    

    答えて

    1

    html_entity_decodeを使用してみてください:

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

    それは – jakson

    +0

    nvm問題を見つけました。 – jakson

    関連する問題