Ver Mensaje Individual
  #7 (permalink)  
Antiguo 09/08/2011, 08:11
sergiop21
 
Fecha de Ingreso: diciembre-2008
Mensajes: 805
Antigüedad: 17 años, 9 meses
Puntos: 20
Respuesta: error al crear con php un archivo xml

esto es lo que tengo

Código PHP:
<?php

require 'Librerias/conn.php';

$db = Conec_con_pass();

$sql_ar = pg_exec($db, "Select * from clientes order by apellido asc limit 10");
$fdev_ar = pg_num_rows($sql_ar);

header("Content-type: text/xml");

/*$salida_xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";*/
$salida_xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"."\n";

for(
$x = 0 ; $x < pg_num_rows($sql_ar) ; $x++)
{
    
$fila = pg_fetch_assoc($sql_ar);
    
$salida_xml .= "<persona>\n";
    
$salida_xml .= "\t<nombre>" . $fila['nombre'] . "</nombre>\n";
    
$salida_xml .= "\t<apellido>" . $fila['apellido'] . "</apellido>\n";
        
// Corregiendo caracteres incorrectos
        
$fila['texto'] = str_replace("&", "&amp;", $fila['texto']);
        
$fila['texto'] = str_replace("<", "&lt;", $fila['texto']);
        
$fila['texto'] = str_replace(">", "&gt;", $fila['texto']);
    
$salida_xml .= "\t\t<texto>" . $fila['texto'] . "</texto>\n";
    
$salida_xml .= "\t</persona>\n";
    

}

$file=fopen("archivo.xml","w+");
  
fwrite ($file,$salida_xml);
  
fclose($file);


echo 
$salida_xml;


?>