1

我有一系列类别,其中一些带有 & 即活动和娱乐。我的脚本导入这些类别并使用其名称获取每个类别的 ID。即:$cat_id = array(get_cat_id($linearray[0]),get_cat_id($linearray[1]),get_cat_id($linearray[2]),get_cat_id($linearray[3])); 我的脚本然后使用这些类别 ID 将帖子添加到 wp。我的问题是我使用 & 导入的类别没有被导入。这些相同的类别(当发送电子邮件通知时)在 & 处中断电子邮件。有一个简单的解决方法吗?

4

3 回答 3

0

当你写帖子时,&你可以&在那里写,它会被翻译成&没有任何问题。

您也可以使用该str_replace函数将其转换为&例如:

$new_text = str_replace('&', '&', $your_string);
于 2010-05-01T12:02:22.390 回答
0

我认为在某些情况下,我为 Wordpress 使用了自己的自定义 sluggify 函数:

function sluggify($text) {
   $text = strtolower(htmlentities($text));
   $text = str_replace("&", "and", $text);
   $text = str_replace("andamp;", "and", $text);
   $text = str_replace(get_html_translation_table(), "-", $text);
   $text = str_replace(" ", "-", $text);
   $text = preg_replace("/[-]+/i", "-", $text);
   return $text;
}

注意两个重复的行:

$text = str_replace("&", "and", $text);
$text = str_replace("andamp;", "and", $text);

虽然重复,但是很有必要!

对于下面无知的评论者 - 这是一个可重用的函数,您可以在其中传递任何字符串值,它将被重击。因此,适用于上述情况。

于 2018-08-15T09:24:45.233 回答
0

为此有一个 WP 内置函数:

$new_text = wp_specialchars_decode($your_string);

文档中:

将许多 HTML 实体转换为它们的特殊字符。具体处理:&、<、>、"和'。

于 2021-04-07T16:14:11.070 回答