收录日期:2020/10/25 07:30:56 时间:2012-12-23 22:43:38 标签: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" /> 

I need to save the text **Integrate Sailthru API functionality into your Wordpress blog.**

Anyone know how to do this?

It really depends on how much this format might change over time and what you want to rely on as constant. If you want to assume that your html will always start with <div class="plugin-block"> and the text you want will always be on a line after an h3, you can do something like this:

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

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