0
保存HTML標籤變量我有功能<?php the_content(); ?>
wihch生成html標籤:如何使用正則表達式
<p>
<a href="http://127.0.0.1/www/www1/wordpress/wordpressEng/wp-content/uploads/2012/09/page1-img2.jpg">
<img class="alignnone size-full wp-image-82" title="page1-img2" src="http://127.0.0.1/www/www1/wordpress/wordpressEng/wp-content/uploads/2012/09/page1-img2.jpg" alt="" width="219" height="124" />
</a>
</p>
我嘗試提取<img.**./>
但我不sucsses。
財產以後這樣的:
//$String =
<p>
<a href="http://127.0.0.1/www/www1/wordpress/wordpressEng/wp-content/uploads/2012/09/page1-img2.jpg">
<img class="alignnone size-full wp-image-82" title="page1-img2" src="http://127.0.0.1/www/www1/wordpress/wordpressEng/wp-content/uploads/2012/09/page1-img2.jpg" alt="" width="219" height="124" />
</a>
</p>
$String = "the_content()";
$pattern = '/^<img/.*/$/>/';//Take string wich start with "<img" and all between and End in "/>"
preg_match($pattern, substr($subject,3), $StrImg, PREG_OFFSET_CAPTURE);
echo $StrImg[0];
output
//<img class="alignnone size-full wp-image-82" title="page1-img2" src="http://127.0.0.1/www/www1/wordpress/wordpressEng/wp-content/uploads/2012/09/page1-img2.jpg" alt="" width="219" height="124" />
如何設置可變$StrImg
完整的img標籤?
非常感謝。
啓用error_reporting。然後刪除多餘的正斜槓,這是您的分隔符。還有更簡單的方法從HTML中提取片段; DOM前端的效率較低,但如果這種情況不受正則表達式的影響,通常更可取。 – mario