XML Parsing error with accent character

I am getting an XML parsing error whenever my code runs into an accent character such as:

áéíóúâä

Is there some way I can alter my code to handle for these and all other special characters?


<?php 

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

$host = "localhost"; 
$user = "root"; 
$pass = "root"; 
$database = "mydatabase"; 

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

$query = "SELECT * FROM tblclients"; 

$resultID = mysql_query($query, $linkID) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\"?>\n"; 
echo $xml_output."<optc>\n"; 
while ($line = mysql_fetch_assoc($resultID) ) {
  echo "<record>\n";
  foreach($line as $key=>$value)
  	  echo "  <$key>". htmlentities($value) . "</$key>\n";	
  echo "</record>\n";
}
echo '</optc>'; 
?>

Open in new window

DanielAttardAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
To remove carriage return, linefeed and tabulation : preg_replace("/[\n|\r|\t]/", "", $value)


....
while ($line = mysql_fetch_assoc($resultID) ) {
  echo "<record>\n";
  foreach($line as $key=>$value)
          $k = strtr($key,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ', 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
          echo "  <$k>". htmlentities(preg_replace("/[\n|\r|\t]/", "", $value)) . "</$k>\n";  
  echo "</record>\n";
}
....

Open in new window

0
 
DanielAttardAuthor Commented:
What is I also need to handle for a carriage return being entered within the data?  I get a parsing error with any data that has a carriage return within the field data.  Thanks.
0
 
leakim971PluritechnicianCommented:
Hello DanielAttard,

No $key with accent too ?
Try for example :


....
while ($line = mysql_fetch_assoc($resultID) ) {
  echo "<record>\n";
  foreach($line as $key=>$value)
          $k = strtr($key,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ', 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
          echo "  <$k>". htmlentities($value) . "</$k>\n";  
  echo "</record>\n";
}
....

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
DanielAttardAuthor Commented:
Thanks leakim.  
0
 
leakim971PluritechnicianCommented:
You're welcome! Merry Christmas!
0
 
DanielAttardAuthor Commented:
Merry Christmas to you too!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.