所以我在这里有一个非常简单的问题。
当我在逗号分隔的列表上运行 str_replace 函数以删除前面带有逗号的值时,该函数会删除列表中的所有逗号。
我在这里做错了什么?
有问题的对象:
$tags = "16, 17, 18, 20, 21, 22"
$tag_id = "17"
编码:
if (strpos($tags, ', '.$tag_id))
{
//remove this in this format
$new_tags = str_replace(', '.$tag_id, "", $tags);
}
elseif (strpos($tags, $tag_id.', '))
{
//remove this in this format
$new_tags = str_replace($tag_id.', ', "", $tags);
}
else
{
//just remove the number
$new_tags = str_replace($tag_id, "", $tags);
}