duanliaouu965826 2018-04-17 13:16
浏览 39
已采纳

使用php将内容添加到字符串上的位置的最有效方法是什么?

I have a string localhost/uploads/images/photo.jpg, I just want to simply rename it to localhost/upload/images/photo_thumb.jpg, keeping in mind that is a dynamic data and am just using it to simply what I want to achieve. I have tried to use the strpos() function to get the position of the '.' then use it for something(this where I got lost), then another thought came to me use implode. I will appreciate if some can help me figure this out thanks.

<?php
function get_google_image_url($type, $id, $column = 'image', $multi = "",$thumb=''){
  if($multi ==''){
    //check if there is thumbnail add _thumb before extention
    if($thumb != ''){
      $l= $this->db->get_where($type,array($type.'_id'=>$id));
      $n = $l->num_rows();
      if($n >0){
        $value = $l->row()->$column;
        $position = strripos($value,'.');
        return $l->row()->$column;
      }
    }else{
      $l= $this->db->get_where($type,array($type.'_id'=>$id));
      $n = $l->num_rows();
      if($n >0){
        /$value = $l->row()->$column
          $position = strripos($value,'.');
        //this where i got stucked
        //return $l->row()->$column;
      }
    }
  }
}

that's the function am trying to implement it in, but what I want to achieve is what I stated above.

  • 写回答

2条回答 默认 最新

  • dqbh8054 2018-04-17 22:48
    关注

    i think the best way here is to use pathinfo

    something like that should work

    $path_parts = pathinfo('localhost/uploads/images/photo.jpg');
    $strNewName = $path_parts['dirname'].'/photo_thumb.jpg';
    echo $strNewName;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面