[ SYSTEM ]: Linux wordpress 6.1.0-41-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.158-1 (2025-11-09) x86_64
[ SERVER ]: Apache/2.4.66 (Debian) | PHP: 8.2.30
[ USER ]: www-data | IP: 172.19.30.54
GEFORCE FILE MANAGER
/
var
/
www
/
html
/
wordpress
/
wp-content
/
plugins
/
wp-optimize
/
vendor
/
simplehtmldom
/
simplehtmldom
/
docs
/
UPLOAD:
NAME
SIZE
QUICK PERMS
ACTIONS
📁 Debug
SET
[ DEL ]
📁 HtmlDocument
SET
[ DEL ]
📁 HtmlNode
SET
[ DEL ]
📁 css
SET
[ DEL ]
📁 examples
SET
[ DEL ]
📁 faq
SET
[ DEL ]
📄 constants.md
632 B
SET
[ EDIT ]
|
[ DEL ]
📄 index.md
1,155 B
SET
[ EDIT ]
|
[ DEL ]
📄 quick-start.md
2,917 B
SET
[ EDIT ]
|
[ DEL ]
📄 requirements.md
1,332 B
SET
[ EDIT ]
|
[ DEL ]
DELETE SELECTED
[ CLOSE ]
EDIT: quick-start.md
--- title: Quick Start --- Find below sample code that demonstrate the fundamental features of PHP Simple HTML DOM Parser. ## Read plain text from HTML document ```php <?php include_once 'HtmlWeb.php'; use simplehtmldom\HtmlWeb; $html = new HtmlWeb(); echo $html->load('https://www.google.com/')->plaintext; ``` Loads a webpage into memory, parses it and returns the plain text. ## Read plain text from HTML string ```php <?php include_once 'HtmlDocument.php'; use simplehtmldom\HtmlDocument; $html = new HtmlDocument(); echo $html->load('<ul><li>Hello, World!</li></ul>')->plaintext; ``` Parses HTML formatted text and returns the plain text. Note that the parser handles partial documents as well as full documents. ## Read specific elements from HTML document ```php <?php include_once 'HtmlWeb.php'; use simplehtmldom\HtmlWeb; $html = new HtmlWeb(); $html->load('https://www.google.com/'); foreach($html->find('img') as $element) echo $element->src . '<br>'; foreach($html->find('a') as $element) echo $element->href . '<br>'; ``` Loads the specified document into memory and returns a list of image sources as well as anchor links. Note that [`find`](examples/finding-html-elements.md) supports [CSS](https://www.w3.org/TR/selectors/) selectors to find elements in the DOM. ## Modify HTML documents ```php <?php include_once 'HtmlDocument.php'; use simplehtmldom\HtmlDocument; $html = new HtmlDocument(); $html->load('<div id="hello">Hello, </div><div id="world">World!</div>'); $html->find('div', 1)->class = 'bar'; $html->find('div[id=hello]', 0)->innertext = 'foo'; echo $html; // <div id="hello">foo</div><div id="world" class="bar">World!</div> ``` Parses the provided HTML string and replaces elements in the DOM before returning the updated HTML string. In this example, the class for the second `div` element is set to `bar` and the inner text for the first `div` element to `foo`. Note that [`find`](examples/finding-html-elements.md) supports a second parameter to return a single element from the array of matches. Note that attributes can be accessed directly by the means of magic methods (`->class` and `->innertext` in the example above). ## Collect information from Slashdot ```php <?php include_once 'HtmlWeb.php'; use simplehtmldom\HtmlWeb; $html = new HtmlWeb(); $html->load('https://slashdot.org/'); $articles = $html->find('article[data-fhtype="story"]'); foreach($articles as $article) { $item['title'] = $article->find('.story-title', 0)->plaintext; $item['intro'] = $article->find('.p', 0)->plaintext; $item['details'] = $article->find('.details', 0)->plaintext; $items[] = $item; } print_r($items); ``` Collects information from [Slashdot](https://slashdot.org/) for further processing. Note that the combination of CSS selectors and magic methods make the process of parsing HTML documents a simple task that is easy to understand.