鍍金池/ 問答/Java  PHP/ 關于PHP正則問題

關于PHP正則問題

以下是文章內(nèi)容

<p>文章內(nèi)容
<img src="/images/nerong.jpg">
<img src="http://www.xxx.com/images/ner...;>
<img src="/images/pic/nerong.jpg">
<img src="/file/pic/nerong.jpg">
文章測試內(nèi)容</p>

使用PHP,把沒有http的圖片地址替換成帶http域名的圖片..給沒有域名的圖片添加域名http://www.xxx.com

回答
編輯回答
熟稔
$html = '<p>文章內(nèi)容
<img src="/images/nerong.jpg">
<img src="http://www.xxx.com/images/nerong.jpg">
<img src="/images/pic/nerong.jpg">
<img src="/file/pic/nerong.jpg">
文章測試內(nèi)容</p>';
$html = str_replace('src="/','src="http://www.xxx.com/',$html);
2018年9月13日 17:15