您当前的位置: 首页 >  sql

漏刻有时

暂无认证

  • 0浏览

    0关注

    717博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

php替换mysql数据库中逗号组成的字符串的解决方案

漏刻有时 发布时间:2022-04-13 10:37:21 ,浏览量:0

项目说明
  1. experts 专家表中字段以"1353416,1353417,1353418,1353419"以固定格式组成的字符串:手机号+“,”分隔符。
  2. 需要在专家未评审前,读取对应的数据记录;
  3. 专家评审后,生成对应的评审记录,取消项目信息字段内的管理信息;
筛选读取sql语句

LOCATE(substr,str) 返回字符串substr中第一次出现子字符串的位置 str。

  • 当检索出匹配结果,返回值>0,代表数据表中存在对应的数据记录。
 $filter_condition = " WHERE locate(" . $_COOKIE['user_phone'] . ", pro_experts4) > 0";
str_ireplace 函数替换
  • 当专家审批完成后,取消原数据表experts的关联信息。如某专家的手机号为135****3416,审批成功后,experts手机号被替换为空。
解决方案

存在的可能性:

  • 135----3415,135----3416 号码在后面,替换时需替换,135****3416
  • 135----3416,135----3415号码在后面,替换时需替换 135****3416,
  • 135----3415,135----3416,135----3417,号码在中间时,需替换135----3416,以及“,,”为“,”

str_ireplace(find,replace,string,count) str_ireplace() 函数替换字符串中的一些字符(不区分大小写)。

    $pre_experts1 = str_ireplace($_COOKIE['user_phone'], '', $role_experts);
    $pre_experts = str_ireplace(',,', '', $pre_experts1);
        //去头掐尾;
        if (substr($pre_experts, -1) == ",") {
            $pre_experts = substr($pre_experts, 0, strlen($pre_experts) - 1);
        }
        if (substr($pre_experts, 0, 1) == ",") {
            $pre_experts = str_ireplace(',', '', substr($pre_experts, 0));
        }

@lockdata.cn

关注
打赏
1661217259
查看更多评论
立即登录/注册

微信扫码登录

0.0409s