簡體   English   中英

PHP替換圖像內容

[英]PHP replace image content

我不是Regex的專家,但我正在嘗試將圖片URL轉換為另一個並刪除高度和寬度屬性......

$content = preg_replace('/src="([^"]*)(png|jpeg|jpg|gif|bmp)"/', 'src="http://www.mysite.com/thumb.php?url=$1&width=500&height=500"', $post_content);

$content = preg_replace( '/(width|height)=\"\d*\"\s/', "", $content);

echo $content;

回應結果並沒有給我一個圖像擴展:

<img src="http://www.mysite.com/thumb.php?url=http://www.mysite.com/wp-content/uploads/2013/02/image.&width=500&height=500" />

我怎樣才能做到這一點?

替換字符串中的$1指的是正則表達式的第一個捕獲組 換句話說, $1的值是正則表達式中第一個(...)匹配的字符序列。

問題是,您的第一組括號不包含文件擴展名 - 因此結果中缺少文件擴展名。

暫無
暫無

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

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