我是preg_replace
的新手,並且有問題。PHP使用preg_replace替換文本,但不是圖像源
我有這樣的文字
$text = 'welcome to example.com site and this is image from example.com <img alt="image of example.com site" src="http://example.com/image.jpg"/> have a nice day!';
是有可能使結果變得
welcome to yyy.com site and this is image from yyy.com <img alt="image of yyy.com site" src="http://example.com/image.jpg"/> have a nice day!
就像你在這裏看到,上純文本和alt example.com變化到yyy.com但不在img源碼,IMG SRC仍然去example.com(我想保持它那樣)
如果有可能使替換不區分大小寫,那麼eXample.com examplE.com exAmPLe.com全部替換爲yyy.com
注意:在某些img中,它們具有alt屬性,但其中一些不具備alt屬性
所以你想保留圖片標籤和文字後? –
是的,先生我想保持圖像源url – prabowo