I am trying to put HTML file content into a body part of a content type.

Procedure: When user uploads a zip file I will extract and replace <img src="path" with different path and put that replaced content into body of the content type. This will be done in hook_node_presave().


               if(trim($unzipped_filename) == 'index.html') {
                    $renamed_filename = $unzipped_path . '/testing.html';
                    //rename the index.html
                    $renaming_index = rename($unzipped_files[0],$renamed_filename);

                    //open file and get data
                    $htmldata = file_get_contents($renamed_filename); 
                    //Match all img src tags from html file        
                    preg_match_all('/<img\s.*?\bsrc="(.*?)".*?>/si', $htmldata, $matches);
                    $i = '';
                    $replacewith = array();
                    for ($i = 0; $i < count($matches[1]); $i++) {
                     //Store replacing strings in an array
                      $replacewith[] = base_path() . $unzipped_path . $matches[1][$i];
                    //Replace all img src tags from html file                 
                    $replacedhtml = str_replace($matches[1], $replacewith, $htmldata);

                    file_put_contents($unzipped_path . 'renamed.html', $replacedhtml);
                    $node->body['und'][0]['value'] = $replacedhtml;


In the above code $node->body['und'][0]['value'] = $replacedhtml; like this I am placing replaced content of HTMl into body part.

Problem: In database I can see all the Tags: etc. But in content its not displaying these tags. Because of this, its not taking JS and css files to load the content. Below html content is not displaying in body.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEXT Example</title>
<link href="css/Academy-style.css" rel="stylesheet" type="text/css"/>

<script src="js/jquery.min.js"></script>
 <script src="js/css3-animate-it.js"></script>

So where I am going wrong please suggest.


Have a look at your configured input format settings. It is likely the input format or a specific filter are stripping HTML tags out.


As Vincent said, its a logic of configuration part of CkEditor.

Advanced Content Filter was stripping these tags.

Hope it helps somebody..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.