簡體   English   中英

如何從特定字符開始字符串並刪除不需要的字符

[英]how to start string from specific character and remove unwanted characters

我有看起來像這樣的文件的URL

movieImages/1`updateCategory.PNG

它應該看起來像這樣

updateCategory.PNG

找到不需要的字符的位置,然后在該位置之后拾取子字符串。

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

輸出量

updateCategory.PNG

小提琴

也就是說,字符串的結構和大小可以不同。 如果第一部分始終保持不變,則可以使用str_replace刪除不需要的內容。

echo str_replace('movieImages/1`','',$str);

你可以這樣使用,簡單

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

輸出將是updateCategory.PNG

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM