我有一個例子:如何在php的img標籤上使用preg_replace類和src?
<a href="http://test.html" class="watermark" target="_blank">
<img width="399" height="4652" src="http://test.html/uploads/2013/10/10.jpg" class="aligncenter size-full wp-image-78360">
</a>
我使用的preg_replace改變值類img標籤
$content = preg_replace('#<a(.*?)href="([^"]*/)?(([^"/]*)\.[^"]*)"([^>]*?)><img(.*?)src="([^"]*/)?(([^"/]*)\.[^"]*)"([^>]*?)></a>#', '<a href=$2$3 class="fancybox"><img$1src="http://test.html/uploads/2013/10/10_new.jpg"></a>', $content);
的標籤和src怎樣的結果?
<a href="http://test.html" class="fancybox" target="_blank">
<img width="399" height="4652" src="http://test.html/uploads/2013/10/10_new.jpg" class="aligncenter size-full wp-image-78360">
</a>
因此簡化 - 你想找到''與類'watermark'的元素和類更改爲'fancybox',然後追加包含''
的用'_new'的src的文件名? –
SmokeyPHP