给出以下字符串
http://thedude.com/05/simons-cat-and-frog-100x100.jpg
Run Code Online (Sandbox Code Playgroud)
我想使用substr或trim(或任何你认为更合适的东西)来返回它
http://thedude.com/05/simons-cat-and-frog.jpg
Run Code Online (Sandbox Code Playgroud)
也就是说,删除-100x100.我需要的所有图像都会在扩展名之前标记到文件名的末尾.
似乎有关于SO和Ruby和Python的响应,但不是PHP /特定于我的需求.
有什么建议?
Sam*_*son 25
如果要匹配任何宽度/高度值:
$path = "http://thedude.com/05/simons-cat-and-frog-100x100.jpg";
// http://thedude.com/05/simons-cat-and-frog.jpg
echo preg_replace( "/-\d+x\d+/", "", $path );
Run Code Online (Sandbox Code Playgroud)
演示:http://codepad.org/cnKum1kd
使用的模式非常基本:
/ Denotes the start of the pattern - Literal - character \d+ A digit, 1 or more times x Literal x character \d+ A digit, 1 or more times / Denotes the end of the pattern
Woj*_*ekT 16
$url = "http://thedude.com/05/simons-cat-and-frog-100x100.jpg";
$new_url = str_replace("-100x100","",$url);
Run Code Online (Sandbox Code Playgroud)
$url = str_replace("-100x100.jpg", '.jpg', $url);
Run Code Online (Sandbox Code Playgroud)
使用-100x100.jpg防弹解决方案.
| 归档时间: |
|
| 查看次数: |
33900 次 |
| 最近记录: |