我需要从数据库中删除以逗号分隔形式的图像名称

我用下面的方法..

名称在数据库中:31.jpg,31 copy.jpg,110 copy.jpg,110.jpg,110 copy-1.jpg,

爆炸后:

Array
(
    [0] => 31.jpg
    [1] => 31 copy.jpg
    [2] => 110 copy.jpg
    [3] => 110.jpg
    [4] => 110 copy-1.jpg
    [5] =>
)


要以逗号删除img名称:110.jpg,

现在结果为:31 copy.jpg,110 copy.jpg,110.jpg,110 copy-1.jpg,

但是为什么会出现110.jpg

以上方法的代码。

<?php

    require("include/config.inc.php");

    $parent_img_id = 184;
    $child_imgs_id = 1221;
    $delimg = '110.jpg';

    $getInfoChild_imgs = mysql_query("select * from parent where parent_img_id = '$parent_img_id' and child_imgs_id = '$child_imgs_id' and child_imgs like '%$delimg%'") or die(mysql_error());

        if(mysql_num_rows($getInfoChild_imgs)>0){
            $result = mysql_fetch_array($getInfoChild_imgs);

            $child_imgs_name =$result['child_imgs'];
            $child_imgs_name = explode(',', $child_imgs_name); // Explode into array


            $deleteImgName = $delimg.',';

            unset($child_imgs_name[ array_search($deleteImgName, $child_imgs_name) ]);

            $child_imgs_name = implode(',',$child_imgs_name);

     }
?>

最佳答案

$deleteImgName110.jpg,

数组没有110.jpg,。它有110.jpg

使用,爆炸时,元素不包含任何逗号。

$deleteImgName = $delimg.','更改为$deleteImgName = $delimg;

关于php - 从PHP中逗号分隔的字符串中删除特定的关键字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13739539/

10-14 15:08
查看更多