在div中获取文本

时间:2010-09-07 01:52:00

标签: php regex html-parsing

<div class="plugin-block"> 
<h3><a href="http://wordpress.org/extend/plugins/sailthru-triggermail/">Sailthru</a></h3> 
**Intergrate Sailthru API functionality into your WordPress blog.** 
<ul class="plugin-meta"> 
    <li><span class="info-marker">Version</span> 1.0</li> 
    <li><span class="info-marker">Updated</span> 2010-9-7</li> 
    <li></li> 
    <li> 
        <span class="info-marker left">Average Rating</span> 
        <div class="star-holder"> 
            <div class="star star-rating" style="width: 0px"></div> 
            <div class="star star5"><img src="http://wordpress.org/extend/plugins-plugins/bb-ratings/star.gif" alt="5 stars" /></div> 
            <div class="star star4"><img src="http://wordpress.org/extend/plugins-plugins/bb-ratings/star.gif" alt="4 stars" /></div> 
            <div class="star star3"><img src="http://wordpress.org/extend/plugins-plugins/bb-ratings/star.gif" alt="3 stars" /></div> 
            <div class="star star2"><img src="http://wordpress.org/extend/plugins-plugins/bb-ratings/star.gif" alt="2 stars" /></div> 
            <div class="star star1"><img src="http://wordpress.org/extend/plugins-plugins/bb-ratings/star.gif" alt="1 star" /></div> 
        </div> 
    </li> 
</ul> 
<br class="clear" /> 

我需要保存文字**Integrate Sailthru API functionality into your Wordpress blog.**

任何人都知道怎么做?

1 个答案:

答案 0 :(得分:0)

这实际上取决于这种格式可能会随着时间的推移而改变多少以及您希望依赖的常量。如果你想假设你的html总是以<div class="plugin-block">开头,你想要的文字总是在h3之后的一行上,你可以这样做:

$pattern = '/plugin-block(?:\n|.)*?<\/h3>\s*(.+)/';
preg_match($pattern, $html, $matches);

echo $matches[1]; //**Intergrate Sailthru API functionality into your WordPress blog.**