だから私はここでかなり単純な問題を抱えています。
コンマで区切られたリストで 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);
}