1

div 内にタグがない 48.20 Lac(s) テキストにアクセスする必要があるため、アクセスできません。これを PHP ファイルで見つける必要があります。一般的なファイルを作成する必要があるため、特定の固定ケースの爆発と内破に依存することはできません。

<div class="priceDetail">
    <b>Total Price :</b>
    <img alt="" src="someimage">48.20 Lac(s)
    <!-- Per Sq Ft Price -->
    <span class="pricePerSqFt">(Price per sq.ft. : Rs. 3,679)</span>
    <!-- Code for price Trends -->
    <span class="priceGrowth">4 %
        <img alt="" src="someimage"
        align="absmiddle">
        <span class="iconWhatisThis">
            <img src="someimage"
            class="whatIcon" align="absmiddle">
            <span style="" id="StoolTip" class="price_main-c"></span>
        </span>
    </span>
    <div class="tt_top-c">
        <span class="priceGrowth"></span>
    </div>
    <div class="tt_mid-c">
        <div class="tt_pointer-c"></div>
        <div>
            <span class="tt_txt-c">Per sq.ft. price for this property is
                <b>higher than the average</b>property price in this locality as per MagicBricks.com
                Price Trends.</span>
        </div>
        <span class="tt_txt-c">
            <span class="tp_txt">To know more about this
                <a href="#priceTrends" onclick="swithTab('priceTrends', tabbedDivArray);">Click
Here</a>
            </span>
        </span>
    </div>
    <div class="tt_bot-c"></div>
</div>
4

2 に答える 2

5

DOM パーサーでできる限り多くの作業を行い、テキストのランダムなロードが残っている場合は、この RegEx で必要なビットを引き出します。

([0-9]{1,5}?\.[0-9]{2} Lac\(s\))

結果

48.20 Lac(s)

(正規表現の 5 を、小数点の前に許可する桁数に変更します)

于 2012-07-05T09:05:41.160 に答える
4

ここに、おそらく正規表現よりも堅牢なDomDocumentを使用したソリューションがあります。

$DOM = new DOMDocument;
$DOM->loadHTML($str);

//Get all the image tags
$elem = $DOM->getElementsByTagName('img');
//Get the first Image
$first = $elem->item(0);
//Get the node after the image
$txt=  $first->nextSibling;
//Get the text
echo $txt->nodeValue;

もちろん、テキストは常にdivの最初の画像の後に配置する必要があります。

于 2012-07-05T09:23:42.340 に答える