我有<?php the_content(); ?>
生成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.**./>
但我不成功。
类似于:
//$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 标签?
非常感谢。