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条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看