dping1968 2015-02-16 23:58
浏览 20

如何在字符串中的最后一个短划线后获得部分?

im new to php and i still dont know all, but here is what i need.

$entry= "Beyonce - Halo.mp3"

I seperate artist and title using this

"artist" => basename(strstr(" ".ucwords($entry), "- ", true )),
"title" => basename(substr(strrchr(ucwords($entry), "- "), 1), ".mp3"),

Can anyone tell me how to get the next text after " - " not from last, because in some cases we had song like this

$entry= "Beyonce - Halo - AlbumName.mp3"

and it get the "AlbumName" as title and its wrong! How can i fix it? Thank you.

  • 写回答

1条回答 默认 最新

  • douningle7944 2015-02-17 00:04
    关注

    The title of your post is a bit confusing because I don't see anything about directories in your post, but I'm assuming you're looking at files on the filesystem, and you want to separate out things like the artist and song name based on either the file name or the directory they are contained in.

    That being said, you can try out the php explode() function!

    So you might use it like this:

    $array_of_piece = explode('-', $song_title);

    then you'd end up with an array consisting of pieces like:

    ('Beyonce ', ' Halo ', ' Albumname.mp3')

    You could also split on ' - ' to get rid of some of the white space as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂