2017-01-11 7 views
1

Stage One div内のテキストを選択するにはどうすればいいですか?それは "field-name-field-stage-one"という一意の名前を持っています。私は要約をエコーし​​たい。ウェブサイトへXPathセレクター(クラス別)

リンク:http://fosterinnovationculture.com/drupalc/?q=node/17

これは私がこれまで持っているものです。

$doc = new DomDocument; 
$some_link = 'http://fosterinnovationculture.com/drupalc/?q=node/17'; 
$tagName = 'div'; 
$attrName = 'class'; 
$attrValue = 'field-name-field-stage-one'; 

$doc->validateOnParse = true; 
$doc->loadHtml(file_get_contents($some_link)); 

$xpath = new DOMXpath($doc); 
$elements = $xpath->query("/html/body//div[contains(@class,'$attrValue')]"); 

答えて

0

field-itemクラスと内側の要素を取得し、nodeValue値を抽出:

$elements = $xpath->query("/html/body//div[contains(@class,'$attrValue')]/div[contains(@class, 'field-item')]"); 
print_r($elements[0]->nodeValue); 

版画:

The survey results show that your organization is ‘interested’ in design-led innovation, which is stage 1 in our framework. 

‘Interested’ means that some people in the organization are noticing design contributions and the methods designers use. Some individuals are experiencing success in a few projects.  The use of design methods is ad hoc, unintentional and happening at a grass roots level. Design continues to be perceived as an added cost to the development process. As a result, there is little executive support or buy-in. 
+0

もし変数にテキストを保存したいのであれば '$ stage = $ elements [0] - > nodeValue;'と同じくらい簡単です。 – marcos

+0

@marcosよ、私のために働く。 – alecxe