Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/04/2008, 00:22
Avatar de dsintekzombie
dsintekzombie
 
Fecha de Ingreso: abril-2008
Mensajes: 14
Antigüedad: 16 años
Puntos: 0
Modificar un XML desde un PHP

Un saludos a todos por aqui, es mi primer post, desde hace tiempo visito la web y decidi unirme...

El dilema que tengo es que tengo un php y un xml, el xml es cargado desde un swf el cual muestra informacion, todo bien hasta aqui..

El php tiene un formulario el cual tiene los campos necesarios para editar el xml, al guardar, el xml lo hace correctamente, pero si despues entro al php a querer editar los campos del xml, hace una cosa rara, si a mi campo le anexo "Hola a todos, saludos désde mi ciudad", el php me sale: "ésde mi ciudad". parece que solo carga a partir del ultimo caracter especial, es lo que me muestra problemas, les muestro el codigo del php:

Código PHP:
<?php
require dirname(__FILE__).'/includes/functions.php';
require 
dirname(__FILE__).'/includes/header.php';

// get menu.xml file
$p =& new xmlParser();
$p->parse('pagina1.xml');
$settings $p->output[0]['child'];

$popups $settings[3]['content'];

?>

        <h1>Pagina 1</h1>
          <hr />
        <form action="save_page1.php" method="post">
          <p>&nbsp;</p>
          <table width="294" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="227"><p>Titulo:<br />
                    <input name="header" type="text" id="header"  value="<?php echo utf8_decode($settings[0]['content']); ?>" />
              </p>
                <p>Contenido:<br />
                    <textarea name="content" cols="35" rows="10" id="content"><?php echo utf8_decode($settings[1]['content']); ?></textarea>
                </p>
                <p>Autor:<br />
                    <input name="author" type="text" id="author" value="<?php echo utf8_decode($settings[2]['content']); ?>" />
                </p>
                <p>Comentarios:<br />
                    <input name="comment" type="text" id="comment" value="<?php echo utf8_decode($settings[3]['content']); ?>" />
                </p>
                <p>
                  <input type="submit" value="guardar cambios"/>
                </p></td>
            </tr>
          </table>
          <p>&nbsp;</p>
</form>
<?php
require dirname(__FILE__).'/includes/footer.php';
?>

Este archivo necesita de otro llamado save_page.php:

Código PHP:
<?php
//check user
require dirname(__FILE__).'/includes/check_user.php';

require 
dirname(__FILE__).'/includes/functions.php';

//get the post variables
$header utf8_encode($_POST['header']);
$content utf8_encode($_POST['content']);
$author utf8_encode($_POST['author']);
$comment utf8_encode($_POST['comment']);

$filename realpath("../pagina1.xml");

//make xml
$xml "<news>
    <header>$header</header>
    <content>$content</content>
    <comment>$author</comment>
    <author>$comment</author>
</news>"
;

/*
<news>
    <header>$border</header>
    <content>$border</content>
    <comment>$border</comment>
    <author>$border</author>
</news>
*/

// make sure xml exists and is writable
if (is_writable($filename)) {
    
//open the file
   
if (!$handle fopen($filename'wb')) {
         
error("Cannot open file");
         exit;
   }

   
// writing new xml
   
if (fwrite($handle$xml) === FALSE) {
       
error("Cannot write to file");
       exit;
   }
   
   
fclose($handle);

} else {
   
error("settings.xml does not seem to be writable. Check that you have changed its CHMOD settings to 777.");
}

//go back to settings page
header("Location:pagina1.php");
?>
Que opinan?

Nota: La verdad no se mucho sobre php, disculpen si omito algo, si es asi, diganme para exponerlo.