如何通过PHP处理XML输出中的水平省略号(三个点)字符 [英] how to handle horizontal ellipsis (three dots) character in XML output through PHP

查看:28
本文介绍了如何通过PHP处理XML输出中的水平省略号(三个点)字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如问题中所述,我正在尝试使用 PHP 生成 XML 输出(用于 iPhone 应用程序),该输出从 MySQL 的文本字段中读取数据.

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.

每当字段中出现水平省略号字符时... XML 无法正确生成.

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']); 

我基本上有两个问题,

  1. 如何处理水平省略号?

  1. How do I handle horizontal ellipsis chracter?

还有更多这样的字符会导致这样的问题吗?对此列表及其解决方案的任何参考都会很棒!

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

谢谢

推荐答案

在 XML 输出中使用文字、实际字符是可能的(也是推荐的方式).不要使用基于 HTML 实体的解决方法 - 这是不必要的.

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.

它对您不起作用的原因可能是省略号字符的编码与正在生成的 XML 文件的编码不匹配.

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.

您只需要确保它们匹配即可.例如,如果您要生成 UTF-8 XML 文件,则省略号字符也必须是 UTF-8.

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.

这篇关于如何通过PHP处理XML输出中的水平省略号(三个点)字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆