我將如何取代這個:用正則表達式操縱IMG SRC -php
http://example.com/myfolder/files/year/month/imagename-widthxheight.imageextension
這樣:
http://example.com/myfolder/files/year/month/imagename-300x300.imageextension
任何幫助嗎?
我將如何取代這個:用正則表達式操縱IMG SRC -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實際值將在您的實際需要而有所不同。所以我認爲最好通過變量傳遞這些值。
讓我展示一些真正的內容:' Torinóiló - 都靈馬 - 都靈atı,Tarr'ın2011年電影。 IMDB sayfası burada.' – marcieng 2012-02-07 09:51:58
如果您想對全圖像標籤進行操作,那麼您也可以使用此操作。 echo preg_replace(「/((\ d {1,7})x(\ d {1,7})\。)/」 ,「300x300。」,'Torinóiló - 都靈馬 - 都靈atı,Tarr'ın2011yapımı電影。'); – 2012-02-07 23:41:03
如何:
$new_img = preg_replace("~([^/]+)-widthxheight(\.[^.]+)$~i","$1-300x300$2",
"http://www.mysite.com/myfolder/files/year/month/imagename-widthxheight.imageextension");
這部分 「寬x高」 不是文字,而是 「老」 的決議一樣123x456,對不對? – djot 2012-02-06 11:15:06
是的。它是可變的。用戶上傳不同尺寸的照片。系統產生300x300的拇指。調整大小和作物。 – marcieng 2012-02-07 09:10:24