Error: Extra content at the end of the document

0

This is the php code where I want to generate an XML from the queries in MySQL:

<?php
header('Content-type: text/xml');

$xmlout = "<?xml version=\"1.0\" ?>\n";
$xmlout .= "<persons>\n";

$db = new PDO('mysql:host=xxxx;dbname=xxxx','xxxx','xxxx');
$stmt = $db->prepare("select * from wp_cf7dbplugin_submits");
$stmt->execute();
while($row = $stmt->fetch()){
 $xmlout .= "\t<person>\n";
 $xmlout .= "\t\t<rut>".$row['rut']."</rut>\n";
 $xmlout .= "\t\t<nombre>".$row['nombre']."</nombre>\n";
 $xmlout .= "\t\t<apellido>".$row['apellido']."</apellido>\n";
 $xmlout .= "\t\t<correo>".$row['correo']."</correo>\n";
 $xmlout .= "\t\t<telefonomovil>".$row['telefonomovil']."</telefonomovil>\n";
 $xmlout .= "\t\t<carrera>".$row['carrera']."</carrera>\n";
 $xmlout .= "\t</person>\n";
}

$xmlout .= "</persons>";
echo $xmlout;
?>

When I execute it, it gives me the following message:

This page contains the following errors:

error on line 115 at column 11: Extra content at the end of the document Below is a rendering of the page up to the first error.

What could it be?

    
asked by Rolly Chin 26.07.2017 в 23:55
source

1 answer

0

The problem is not PHP itself, but you are not generating the XML correctly. Check the source code in the browser, specifically on line 115, column 11 (which is where the error is displayed), there may be a character that is breaking the structure, perhaps greater than or less than.

Maybe you're using htmlentities () for each column that you can contain these characters.

    
answered by 27.07.2017 в 04:33