PHP 帮助将变音符号转换为 HTML 引号

发布于 2024-09-25 13:53:07 字数 294 浏览 0 评论 0原文

我有一堆 MS Word 文件,客户希望将其显示在他的网站上。我已经使用“另存为网页”将它们转换为 HTML——是的,我知道这会产生糟糕的 HTML,但我尝试过的其他方法会丢失嵌入图像的链接。

在大多数情况下,我可以使用 PHP 来清理显示,但有一项让我完全困惑:所有单引号和双引号都以带有变音符号(重音符号)的各种字母的形式出现,我不知道如何检测它们,并且将它们转换为正确的 HTML 实体。例如:Õ(O 波形符)应为单引号,Ò(O 坟墓)应为左双引号,Ó(O 尖号)应为右双引号。我尝试过 htmlentities、inov 和许多其他方法,但没有成功。

I have a bunch of MS Word files that a client wants displayed on his web site. I've converted them to HTML using "Save as Web Page" -- and yes I know that this produces lousy HTML but other methods I've tried lose the links to the imbedded images.

For the most part, I can use PHP to clean up the display but one item has me completely baffled: All single and double quotes are coming through as various letters with diacritics (accents) and I can't figure out how to detect them and convert them to the correct HTML entities. For example: Õ (O tilde)should be single-quote, Ò (O grave) should be open double-quote, Ó (O acute) should be close double-quote. I've tried htmlentities, iconv and a bunch of other methods with no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨与橙与城 2024-10-02 13:53:07

言语一片混乱!对于单个文件,我会执行以下操作: http://word2cleanhtml.com/

如果这将是一个持续的过程事实上,有整个文件库专门用于对 Web 的 Word 文档进行去字处理。尝试 HTML TidyHTML Purifier

如果您要使用 WYSIWYG 类型的工具并且正在进行中,CKEditor 将自动删除 Word HTML 垃圾。 CK 与 TinyMCE 和其他产品的区别在于,即使用户忘记执行“从 Word 复制”,它仍然不会允许不良内容通过。

自从使用 CK 和 Tidy 以来,尽管数百名具有不同网络知识水平的用户都在使用我的公司网站,但我的公司网站没有出现任何问题。在进行更改之前,这几乎是每天都会遇到的问题。

Word is a mess! For individual files I run through something like this: http://word2cleanhtml.com/

If this is going to be an ongoing thing, there are entire file libraries dedicated to de-word-ifying Word documents for the web. Try HTML Tidy or HTML Purifier

If you're going to be dealing with a WYSIWYG type tool and this is ongoing, CKEditor will automatically drop Word HTML garbage. The thing that differentiates CK from TinyMCE and others is that even if the user forgets to do "Copy From Word" it still will not allow the bad stuff through.

Since using CK and Tidy, I've not had a single problem on my company's site despite being used by hundreds of users with varying levels of web knowledge. Prior to the changes, it was a near-daily issue.

不甘平庸 2024-10-02 13:53:07

我建议在编辑器中打开那些糟糕的 html 文件,例如: Notepad++ ,然后进行搜索并替换所有内容打开文档。

I suggest open those lousy html files into an editor like: Notepad++ and just do a search and replace in all open documents.

天暗了我发光 2024-10-02 13:53:07

Word文档的编码是什么?您可以尝试通过 PHP 匹配原始编码,或者将 Word 文档的编码更改为 UTF-8 之类的编码,并确保您的页面也显示为 UTF-8。

What's the encoding of the Word Document? You can either try to match the original encoding through PHP or change the encoding of the Word Document to something like UTF-8 and make sure your page is displayed as UTF-8 as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文