[英]manipulating img src with regex -php
我该如何替换它:
http://example.com/myfolder/files/year/month/imagename-widthxheight.imageextension
对此:
http://example.com/myfolder/files/year/month/imagename-300x300.imageextension
任何帮助?
你可能想试试这个
// if your src has widthxheight are specified literally like that you may try
echo preg_replace("/\W{0,1}(width).*(height)/i","-300x300","http://www.mysite.com/myfolder/files/year/month/imagename-widthxheight.imageextension");
// if your src has widthxheight are specified in int val you may try
echo preg_replace("/\W{0,1}(\d{1,7}).*(\d{1,7})/i","-300x300","http://www.mysite.com/myfolder/files/year/month/imagename-123x456.imageextension");
实际值-300x300将根据您的实际需求而有所不同。 所以我认为最好通过变量传递这些值。
怎么样:
$new_img = preg_replace("~([^/]+)-widthxheight(\.[^.]+)$~i","$1-300x300$2",
"http://www.mysite.com/myfolder/files/year/month/imagename-widthxheight.imageextension");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.