如何删除wordpress中的特殊字符?

发布于 2024-12-05 16:46:59 字数 433 浏览 1 评论 0原文

我正在使用 Topsy,它返回我的 mebsite 排名最高的文章的标题,它返回我一个 RSS 文件,其中包含带有链接的帖子标题。现在我只获取帖子名称并使用帖子标题尝试使用以下函数在 mysql 数据库中进行搜索:

get_post_by_title($postTitle,'post');

但问题是 topsy 返回我的帖子标题,但它还在 RSS 文件中添加了一些特殊字符,例如“'”替换为“ ' ” 这个字符。因为这个 get_post_by_title() 函数不会按标题名称返回我的帖子。

编辑:它返回给我一个这样的帖子标题:

iPad Applications In Bloom’s Taxonomy NEXT

这里单引号是特殊字符。

请帮我。谢谢

I am using Topsy, It returns me title of highest ranking article of my mebsite, It returns me one RSS file which contains post title with there link. For now i am only taking post name and using post title am trying to search in mysql database using following function like this:

get_post_by_title($postTitle,'post');

But the problem is topsy returns me post title but it also add some special characters in RSS file like " ' " replace with " ’ " this charecters.Because of this get_post_by_title() function does not return me post by title name.

EDIT : It returns me one post title like this :

iPad Applications In Bloom’s Taxonomy NEXT

Here single quote is special charecter.

Please help me. Thanks

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

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

发布评论

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

评论(3

难得心□动 2024-12-12 16:46:59

首先让我们澄清一个误解:示例中的字符不是“特殊”字符。它是 Unicode 代码点 U+2019,“右单引号”。它的 HTML 实体引用是 。这是一个普通字符——它只是碰巧是一个没有 ASCII 表示形式的普通字符。在回答您的具体问题之前,我需要告诉您阅读 Joel Spolsky 的文章“The绝对最低限度 每个软件开发人员绝对、积极地必须了解 Unicode 和字符集(没有任何借口!)” - 这就是它在罐头上所说的,除非您至少吸收了更多关于 Unicode 的知识,你会不断遇到这样的问题。不要太担心:每个人都会遇到这样的问题,直到他们学会如何处理文本。 Unicode 并不“难”,而是“容易暴露我们对文本工作方式所做的无意识假设”。 †

现在,回答你的问题。

如果我没理解错的话,您遇到的情况是,您的帖子标题中包含非 ASCII 字符,例如 当您使用以下命令搜索它们时,这些帖子不会显示get_post_by_title() (看起来您正在使用类似于 此问题的接受答案 - 是这样吗?)有两条路径解决方案:以更易于搜索的格式存储标题,或使用可以查找非 ASCII 字符的搜索方法。

以不同方式存储标题需要您通过 PHP 的 内置 htmlentities() 函数或在将它们存储到 WordPress 数据库之前 - 您还需要确保转换没有相当于 '\xNN' 形式的 HTML 实体的字符,并确保您的数据库排序规则/字符集设置为 UTF-8 或其他 Unicode 感知编码。这将是一项不小的努力。 。

使用不同的搜索方法不需要修改数据库或深入了解 WordPress 内部,但确实需要非常仔细地摆弄搜索字符串 您需要在搜索中使用您要查找的确切字符(如有必要,表示为 '\xNN' 字符引用),或者在搜索中谨慎使用通配符。

不管怎样,祝你好运。如果您的更多代码可见,则可能会提供更具体的建议。

†:顺便说一句,如果您使用比 PHP 更好的语言和比 MySQL 更好的数据库,您与 Unicode 相关的生活也会变得更加轻松。 WordPress 与 PHP 和 MySQL 有着千丝万缕的联系:PHP & MySQL MySQL 在正确处理 Unicode 问题方面都表现得可悲、可怕、可笑。如果你根除 PHP 和 PHP,你作为程序员的生活将会变得更好。 MySQL 来自它。

‡:说真的,PHP 太糟糕了不擅长这一点,以及MySQL 正处于摸索的鞋带状态。避开他们。

First let's clear up a misconception: that character in your example is not a "special" character. It is Unicode code point U+2019, "RIGHT SINGLE QUOTATION MARK." Its HTML entity reference is . It's an ordinary character - it just happens to be an ordinary character that has no representation in ASCII. Before getting to an answer to your specific question, I need to tell you to read Joel Spolsky's article "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" - it is just what it says on the tin, and unless you absorb at least a little more knowledge about Unicode, you will keep running into problems like this. Don't fret too much: everyone runs into problems like this until they learn how to deal with text. Unicode isn't "hard" so much as it is "prone to exposing unconscious assumptions we make about how text works." †

Now, to your question.

If I'm reading you right, what's happening to you is that you have posts with non-ASCII characters in their titles such as which aren't showing up when you search for them with get_post_by_title() (it seems like you're using something similar to the accepted answer on this question - is that right?) There are two paths to a solution: store the titles in a format that's easier for you to search, or use a searching method that can find non-ASCII characters.

Storing the titles differently would require that you run them through PHP's built-in htmlentities() function or before storing them in your Wordpress DB - you would also want to make sure that you convert characters with no HTML entity equivalent to '\xNN' form, and to make sure that your DB's collation/charset is set to UTF-8 or another Unicode-aware encoding. This will be a nontrivial amount of effort. ‡

Using a different searching method doesn't require tinkering with your DB or digging into WordPress internals, but it does require very careful fiddling with search string. You'll need to either use the exact character you're looking for in a search, expressed as a '\xNN' character reference if necessary, or use wildcards carefully in the search.

Either way, good luck. It may be possible to offer more specific advice if more of your code is visible.

†: By the way, your life with regards to Unicode will also get much, much easier if you use better languages than PHP and better databases than MySQL. WordPress is inextricably tied to PHP and MySQL: PHP & MySQL are both woefully, horrendous, hilariously bad at handling Unicode issues correctly. Your life as a programmer will get better if you extirpate PHP & MySQL from it.

‡: Seriously, PHP is atrociously bad at this, and MySQL is in a shoelaces-tied-together state of fumbling. Avoid them.

芯好空 2024-12-12 16:46:59

从 wp-config.php 中删除

//define('DB_CHARSET', 'utf8');

//定义('DB_COLLATE','utf8_unicode_ci');

remove from wp-config.php

//define('DB_CHARSET', 'utf8');

//define('DB_COLLATE','utf8_unicode_ci');

眸中客 2024-12-12 16:46:59

您可以使用 preg_replace 轻松删除特殊字符,请参阅这篇文章 -> http://code-tricks.com/filter-non-ascii-字符使用-php/

You can easily remove special characters using preg_replace, see this post -> http://code-tricks.com/filter-non-ascii-characters-using-php/

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