Jump to content

ecrire dans un fichier au format html


Recommended Posts

Bonsoir à tous.

Comme dans le module editorial, qui permet de créer, écrire et lire dans un fichier xml, est il possible de faire la même chose en html ?
Quand je récupère le bout de code, la lecture n'est pas bonne.

   function putContent($xml_data, $key, $field, $forbidden, $section)
   {
       foreach ($forbidden AS $line)
           if ($key == $line)
               return 0;
       if (!preg_match('/^'.$section.'_/i', $key))
           return 0;
       $key = preg_replace('/^'.$section.'_/i', '', $key);
       $field = htmlspecialchars($field);
       if (!$field)
           return 0;
       return ("\n".'        <'.$key.'>'.$field.''.$key.'>');
   }

   function getContent()
   {
       /* display the module name */
       $this->_html = ''.$this->displayName.'';
       $errors = '';

       /* update the editorial xml */
       if (isset($_POST['submitUpdate']))
       {
           // Forbidden key
           $forbidden = array('submitUpdate');

           foreach ($_POST AS $key => $value)
               if (!Validate::isString($_POST[$key]))
               {
                   $this->_html .= $this->displayError($this->l('Invalid html field, javascript is forbidden'));
                   $this->_displayForm();
                   return $this->_html;
               }

           // Generate new XML data
           $newXml = '<?xml version=\'1.0\' encoding=\'utf-8\' ?>'."\n";
           $newXml .= ''."\n";
           $newXml .= '    <header>';
           // Making header data
           foreach ($_POST AS $key => $field)
               if ($line = $this->putContent($newXml, $key, $field, $forbidden, 'header'))
                   $newXml .= $line;
           $newXml .= "\n".'    </header>'."\n";
           $newXml .= '    <body>';
           // Making body data
           foreach ($_POST AS $key => $field)
               if ($line = $this->putContent($newXml, $key, $field, $forbidden, 'body'))
                   $newXml .= $line;
           $newXml .= "\n".'    </body>'."\n";
           $newXml .= ''."\n";

           /* write it into the editorial xml file */
           if ($fd = @fopen(dirname(__FILE__).'/editorial.xml', 'w'))
           {
               if (!@fwrite($fd, $newXml))
                   $errors .= $this->displayError($this->l('Unable to write to the editor file.'));
               if (!@fclose($fd))
                   $errors .= $this->displayError($this->l('Can\'t close the editor file.'));
           }
           else
               $errors .= $this->displayError($this->l('Unable to update the editor file.
Please check the editor file\'s writing permissions.'));

           /* upload the image */
           if (isset($_FILES['body_homepage_logo']) AND isset($_FILES['body_homepage_logo']['tmp_name']) AND !empty($_FILES['body_homepage_logo']['tmp_name']))
           {
               Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);
               if ($error = checkImage($_FILES['body_homepage_logo'], $this->maxImageSize))
                   $errors .= $error;
               elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['body_homepage_logo']['tmp_name'], $tmpName))
                   return false;
               elseif (!imageResize($tmpName, dirname(__FILE__).'/homepage_logo.jpg'))
                   $errors .= $this->displayError($this->l('An error occurred during the image upload.'));
               unlink($tmpName);
           }
           $this->_html .= $errors == '' ? $this->displayConfirmation('Settings updated successfully') : $errors;
       }

       /* display the editorial's form */
       $this->_displayForm();

       return $this->_html;
   }



Quelqu'un aurait il déjà converti xml en html?

xml = <p>bonjour prestashop</p>
html =

bonjour prestashop



Cordialement
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...