duanliang8464 2015-02-13 21:07
浏览 93
已采纳

strrchr函数的反义词是什么?

I want to remove all characters after last specific string. For this function I need opposite of strrchr function.

For example, I want to remove all characters after last "." from "Hello.World.pdf". But with strrchr function I can only remove "Hello.World" before "."!

I want something like this code:

<?php
echo strrchr("Hello.World.pdf" , "." , true);
?>

But this code isn't working!

  • 写回答

3条回答 默认 最新

  • duanchao4445 2015-02-13 21:21
    关注

    If you are dealing with file names that can have various extensions and you would like to remove the extension, you can get the extension using pathinfo() and then use str_replace() to get rid of it:

    $filename  = 'Hello.World.pdf';
    $extension = pathinfo($filename, PATHINFO_EXTENSION);
    $filename  = str_replace('.' . $extension, '', $filename);
    echo $filename; //Hello.World
    

    More info on pathinfo and str_replace

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图