如何从特定字符开始字符串并删除不需要的字符

时间:2016-01-18 06:20:56

标签: php

我有这样的文件的URL

100 Track

它看起来应该是这样的

movieImages/1`updateCategory.PNG

2 个答案:

答案 0 :(得分:1)

Find the position of unwanted character and then pick up the substring after that position.

$str="movieImages/1`updateCategory.PNG";
$unwanted="`";
echo substr($str,strpos($str,$unwanted)+1);

Output

updateCategory.PNG

Fiddle

中包含
  • 标记

    即如果字符串的结构和大小不同。如果第一部分始终保持不变,您只需使用str_replace删除不需要的内容。

    echo str_replace('movieImages/1`','',$str);
    
  • 答案 1 :(得分:1)

    你可以这样使用,简单

    
    
    $string = 'movieImages/1`updateCategory.PNG';
    $ser = 'movieImages/1`';
    $trimmed = str_replace($ser, '', $string);
    echo $trimmed;
    
    
    

    输出将是updateCategory.PNG

    相关问题