style="background-image:url(img/login_08.gif)
等 凡是有以上類型的 以 images img js css 開頭的 js 圖片css檔案
src 或 href = 或 background-image:url() 雙引號的 單引號的 無引號的
都能自動加上一個 /template/進去
變成 比如
style="background-image:url(/template/img/login_08.gif)
謝謝
$html = preg_replace('#(images|img|js|css)/#i', 'template/$1/', $html);
在這個基礎上改進,這個不能判斷是不是 src= href= 還有 有沒單雙引號
回複討論(解決方案)
$s =<<< TXT style="background-image:url(img/login_08.gif)TXT;echo preg_replace('/(href\s*=\s*|url\(|src\s*=\s*)(["\']?)/', '$1$2/template/', $s);
style="background-image:url(/template/img/login_08.gif)
老大 能再加個限制不
只有 帶 images js 或 css 開頭的路徑 才會插入一個 /template/
變成 /template/images/ 或 /template/js/ 或 /template/css/
而其他的 比如 img/ 開頭的 則不變化
根據嘮叨前輩的代碼修改
$s =' style="background-image:url(img/login_08.gif)';echo preg_replace('/(href\s*=\s*|url\(|src\s*=\s*)(["\']?)(Images|js|css)/', '$1$2/template/$3', $s);
執行
style="background-image:url(img/login_08.gif)
謝謝兩位 完美了!