Search code examples
phpxmlellipsis

how to handle horizontal ellipsis (three dots) character in XML output through PHP


As mentioned in the question, I am trying to generate an XML output( for an iPhone app) using PHP which is reading the data from MySQL's text field.

Whenever there is a horizontal ellipsis character in the field... the XML is not generated properly.

I have tried a few ways to escape it like shown below, but none seems to work...

$row['detail'] = str_replace("&", "&", $row['detail']); 
$row['detail'] = str_replace("…", "&hellip;", $row['detail']); //<-- prob is here
$row['detail'] = str_replace("<", "&lt", $row['detail']); 
$row['detail'] = str_replace("\'", "&apos;", $row['detail']); 
$row['detail'] = str_replace(">", "&gt;", $row['detail']); 
$row['detail'] = str_replace("\"", "&quot;", $row['detail']); 

I have 2 questions basically,

  1. How do I handle horizontal ellipsis chracter?

  2. Are there more such characters which could cause such problem? Any reference to this list and its solution would be great!

Thanks


Solution

  • It is possible (and the recommended way) to use the literal, actual character in XML output. Don't use HTML entity based workarounds - it's unnecessary.

    The reason why it doesn't work for you is probably because the ellipsis characters's encoding doesn't match the encoding of the XML file that is being generated.

    You just need to make sure they match. So for example, if you're generating an UTF-8 XML file, the ellipsis character needs to be UTF-8 as well.