2012-07-05 3 views
1

div에 태그가없는 48.20 Lac (s) 텍스트에 액세스해야하는데, 이유는 그것이 액세스 할 수없는 이유입니다. 나는 이것을 PHP 파일에서 찾아야한다. 나는 $ html-> find ('div.priceDetail')을 사용하여 trim (strip_tags ($ result))을 수행하여 48.20 Lac (s) + unnecesary text를 주었다. 일반 파일을 빌드 했으므로 특정한 고정 된 경우에 대해 폭발 및 함몰에 의존 할 수 없습니다.div 요소에 태그가없는 텍스트 찾기

<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

있는 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; 

은 텍스트가 항상 사업부의 첫 번째 이미지 뒤에 위치해야합니다.

+0

빙고 !!!! – user1425322

5

는 DOM 파서와 당신이 할 수있는 텍스트의 사용자 임의의 하중을 떠날 때이 정규식으로 원하는 비트를 꺼내, 많은 작업을 수행

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

결과

48.20 Lac(s) 

(당신은 소수점 전에 허용 할 자릿수에 정규식에 5 변경) 여기
+0

덕분에 많은 친구 ... – user1425322