SimpleHTMLDOM очищает текст между двумя тегами [duplicate]

Используя приведенный ниже код, вы можете получить уникальный идентификатор устройства устройства Android OS в виде строки.

deviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
1
задан silkfire 1 April 2014 в 18:23
поделиться

2 ответа

Если это всегда в одном месте, вы можете сделать:

$html->find('.article text', 4);
1
ответ дан pguardiario 26 August 2018 в 06:45
поделиться

Здесь вам не нужно simple_html_dom. Это можно сделать с помощью DOMDocument и DOMXPath . Оба являются частью ядра PHP.

Пример:

// your sample data
$html = <<<EOF
<div class="article">
 <div style="text-align:justify">
    <img src="image.jpg" title="image">
    <br>
    <br>
    "Text to grab"
    <div>......</div>
    <br></br>
    ................
    ................
  </div>
</div>
EOF;

// create a document from the above snippet
// if you are loading from a remote url use:
//   $doc->load($url);
$doc = new DOMDocument();
$doc->loadHTML($html);

// initialize a XPath selector
$selector = new DOMXPath($doc);

// get the text node (also text elements in xml/html are nodes
$query = '//div[@class="article"]/div/br[2]/following-sibling::text()[1]';
$textToGrab = $selector->query($query)->item(0);

// remove newlines on start and end using trim() and output the text
echo trim($textToGrab->nodeValue);

Выход:

"Text to grab"
3
ответ дан hek2mgl 26 August 2018 в 06:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: