I am trying to select either a class or an identifier using the PHP Simple HTML DOM Parser, completely out of luck. My example is very simple and seems to match the examples given in the manual ( http://simplehtmldom.sourceforge.net/manual.htm ), but it just doesn't work, it forces me up the wall. Other sample scripts defined with a simple dom work fine.
<?php include_once('simple_html_dom.php'); $html = str_get_html('<html><body><div id="foo">Hello</div><div class="bar">Goodbye</div></body></html>'); $ret = $html->find('.bar')->plaintext; echo $ret; print_r($ret);
Can anyone see where I'm wrong?
$html->find('.bar'); will return a collection of matching elements, so you need to pass the index as the second parameter:
$html->find('.bar');
$ret = $html->find('.bar', 0)->plaintext;
:
foreach($html->find('.bar') as $element) { echo $element->plaintext . '<br />'; }
Source: https://habr.com/ru/post/1732990/More articles:Windsor Lock Fluent API: Defining an Array with a Separate Element as a Dependency - apiundefined link to LibSerial - c ++The best database solution for managing massive amounts of data - performanceCheck WinForms TabControl: go to the tab where the check failed. - validationAdding Combobox to DataGridView via Datatable - c #Получение объекта TargetInvocationException с использованием библиотеки Parser для командной строки - c#How to switch to "SMS" mode on an Android keyboard - androidC # Compact-Framework friendly command line parser - parsingCombine text with wildcards in a database? - databaseПрепроцессор llvm g++ проходит - g++All Articles