### Serve MkDocs Project for Local Preview
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/README.md
Commands to start a local development server for the MkDocs project. This allows you to preview the documentation site in a web browser, typically accessible at http://127.0.0.1:8000, before building the final output.
```Shell
mkdocs serve
```
```Shell
python3 -m mkdocs serve
```
--------------------------------
### Check and Install MkDocs Version
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/README.md
Commands to check the installed version of MkDocs and to install or upgrade it using pip. A version of 1.0.4 or higher is recommended. These commands require Python and pip to be installed on the system.
```Shell
mkdocs --version
```
```Shell
python3 -m mkdocs --version
```
```Shell
pip install mkdocs
```
```Shell
python3 -m pip install mkdocs
```
--------------------------------
### Install or Upgrade MkDocs
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/README.md
Commands to install or upgrade MkDocs using pip, in case the installed version is older than required or MkDocs is not yet installed.
```Shell
pip install mkdocs
```
```Shell
python3 -m pip install mkdocs
```
--------------------------------
### Extract Specific Elements from HTML Document using PHP Simple HTML DOM Parser
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/quick-start.md
Loads an HTML document from a URL and demonstrates how to find and extract specific elements using CSS selectors. This example retrieves and prints the 'src' attribute of all image elements and the 'href' attribute of all anchor links.
```php
$html = file_get_html('https://www.google.com/');
foreach($html->find('img') as $element)
echo $element->src . '
';
foreach($html->find('a') as $element)
echo $element->href . '
';
```
--------------------------------
### Collect Information from Slashdot (PHP)
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/quick-start.md
Provides an example of web scraping by loading the Slashdot homepage, using CSS selectors to identify article elements, and extracting specific details like title, intro, and details into a structured array for further processing. This highlights the ease of parsing HTML with CSS selectors and magic methods.
```php
$html = file_get_html('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);
```
--------------------------------
### Collect Information from Slashdot using PHP Simple HTML DOM Parser
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/quick-start.md
Demonstrates how to scrape structured information from a live website (Slashdot.org) by combining CSS selectors and magic methods. It extracts article titles, introductions, and details into an array for further processing, illustrating the parser's ease of use for data collection.
```php
$html = file_get_html('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);
```
--------------------------------
### Check MkDocs Installation Version
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/README.md
Commands to verify the installed version of MkDocs, ensuring it meets the minimum requirement (1.0.4 or higher) for building the project documentation.
```Shell
mkdocs --version
```
```Shell
python3 -m mkdocs --version
```
--------------------------------
### Modify HTML Documents (PHP)
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/quick-start.md
Demonstrates parsing an HTML string, modifying elements within the DOM using `find` and direct attribute access (magic methods), and then outputting the updated HTML string. This example shows how to change an element's class and inner text.
```php
$doc = '
Hello,
World!
';
$html = str_get_html($doc);
$html->find('div', 1)->class = 'bar';
$html->find('div[id=hello]', 0)->innertext = 'foo';
echo $html; // foo
World!
```
--------------------------------
### PHP: Example usage of save method
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/api/simple_html_dom_node/save.md
Illustrates how to call the `save` method in PHP, both without arguments to get the document string and with a filepath to save to a file.
```php
$string = $node->save();
$string = $node->save($file);
```
--------------------------------
### Build MkDocs Project for Deployment
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/README.md
Commands to build the final static site files for the MkDocs project. The generated HTML, CSS, and JavaScript files will be placed in the 'site' folder, ready for deployment to a web server.
```Shell
mkdocs build
```
```Shell
python3 -m mkdocs build
```
--------------------------------
### PHP addClass Method Usage Examples
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/api/simple_html_dom_node/addClass.md
Examples demonstrating how to use the `addClass` method in PHP to add single, multiple space-separated, or array-based class names to a node object.
```php
$node->addClass('hidden');
$node->addClass('article important');
$node->addClass(array('article', 'new'));
```
--------------------------------
### PHP parent() Function API Reference
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/api/simple_html_dom_node/parent.md
Detailed API documentation for the PHP `parent()` function, including its signature, parameters, and behavior for both getting and setting the parent node.
```APIDOC
parent ( [ object $parent = null ] ) : object
Parameter | Description
--------- | -----------
`parent` | The parent node
Returns the parent node of the current node if `$parent` is null.
Sets the parent node of the current node if `$parent` is not null. In this case the current node is automatically added to the list of nodes in the parent node.
```
--------------------------------
### Read Plain Text from HTML Document using PHP Simple HTML DOM Parser
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/quick-start.md
Loads the specified HTML document from a URL into memory, parses it, and returns the plain text content. The `file_get_html` function supports both local and remote files.
```php
echo file_get_html('https://www.google.com/')->plaintext;
```
--------------------------------
### Read Plain Text from HTML Document (PHP)
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/quick-start.md
Demonstrates how to load an HTML document from a URL or local file using `file_get_html` and extract its plain text content. This method supports both remote and local file paths.
```php
echo file_get_html('https://www.google.com/')->plaintext;
```
--------------------------------
### HTML Document Structure Example for Node Types
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/api/definitions.md
Illustrates various HTML elements and text content that correspond to different node types recognized by the parser, such as DOCTYPE, HTML tags, comments, and plain text.
```html
Hello, World!
```
--------------------------------
### PHP: Example usage of save method
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/api/simple_html_dom_node/save.md
Illustrates how to call the `save` method in PHP, both to retrieve the document string and to save it to a specified file.
```php
$string = $node->save();
$string = $node->save($file);
```
--------------------------------
### Modify HTML Documents using PHP Simple HTML DOM Parser
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/quick-start.md
Parses an HTML string, modifies elements within its DOM structure, and then outputs the updated HTML. This example changes the class of a div element and the inner text of another, showcasing direct attribute access via magic methods and the `find` method's ability to return specific matches.
```php
$doc = 'Hello,
World!
';
$html = str_get_html($doc);
$html->find('div', 1)->class = 'bar';
$html->find('div[id=hello]', 0)->innertext = 'foo';
echo $html; // foo
World!
```
--------------------------------
### Extract Specific Elements from HTML Document (PHP)
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/quick-start.md
Illustrates loading an HTML document and using CSS selectors with the `find` method to locate and iterate through specific elements, such as images and anchor links, extracting their attributes like `src` and `href`.
```php
$html = file_get_html('https://www.google.com/');
foreach($html->find('img') as $element)
echo $element->src . '
';
foreach($html->find('a') as $element)
echo $element->href . '
';
```
--------------------------------
### HTML Document Structure Example for Node Types
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/api/definitions.md
Illustrates various HTML elements and text within a single line to demonstrate how an HTML parser categorizes them into different node types, such as elements, comments, text, and unknown types (e.g., DOCTYPE). This example helps in understanding the parser's internal representation of a simple HTML document.
```html
Hello, World!
```
--------------------------------
### PHP: Examples of addClass Method Usage
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/api/simple_html_dom_node/addClass.md
Illustrates various ways to use the `addClass` method in PHP, including adding a single class, multiple classes as a space-separated string, and multiple classes as an array. The method can accept a string or an array for the class names.
```php
$node->addClass('hidden');
$node->addClass('article important');
$node->addClass(array('article', 'new'));
```
--------------------------------
### Read Plain Text from HTML String (PHP)
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/quick-start.md
Shows how to parse a given HTML string, including partial documents, using `str_get_html` and retrieve its plain text content. The parser can handle incomplete HTML structures.
```php
echo str_get_html('')->plaintext;
```
--------------------------------
### PHP hasClass Method Usage Example
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/api/simple_html_dom_node/hasClass.md
Illustrates a practical application of the `hasClass` method in PHP, demonstrating how to invoke it on a `$node` object to check for the existence of the 'article' class.
```php
$node->hasClass('article');
```
--------------------------------
### PHP parent() Method API Documentation
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/api/simple_html_dom_node/parent.md
Comprehensive API documentation for the `parent` method in PHP, outlining its signature, parameter details, return type, and dual functionality for getting or setting the parent node of an object.
```APIDOC
parent ( [ object $parent = null ] ) : object
Description: Returns the parent node of the current node if $parent is null. Sets the parent node of the current node if $parent is not null. In this case the current node is automatically added to the list of nodes in the parent node.
Parameters:
parent:
Type: object
Description: The parent node
Returns: object
```
--------------------------------
### Fetching Remote Content with cURL in PHP
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/faq.md
This example provides an alternative method for fetching remote HTML content using PHP's cURL library. This is particularly useful when `allow_url_fopen` is disabled on the server, offering a robust way to retrieve web pages before parsing them with `str_get_html()`.
```PHP
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://????????');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
$str = curl_exec($curl);
curl_close($curl);
$html= str_get_html($str);
...
```
--------------------------------
### Fetching Remote Content with cURL in PHP
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/faq.md
This example provides an alternative method for fetching remote web page content using PHP's cURL library. It is particularly useful when `allow_url_fopen` is disabled on the server, offering a robust way to retrieve data before parsing it with `str_get_html`.
```PHP
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://????????');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
$str = curl_exec($curl);
curl_close($curl);
$html= str_get_html($str);
...
```
--------------------------------
### Create HTML DOM Objects Functionally (PHP)
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9_1/manual/docs/manual/creating-dom-objects.md
This PHP snippet demonstrates how to parse HTML content into a DOM object using functional helper functions. It shows examples for loading HTML from a direct string, a remote URL, and a local file path. This approach is often used with libraries like Simple HTML DOM Parser.
```php
// Create a DOM object from a string
$html = str_get_html('Hello!');
// Create a DOM object from a URL
$html = file_get_html('http://www.google.com/');
// Create a DOM object from a HTML file
$html = file_get_html('test.htm');
```
--------------------------------
### HTML Attribute Quoting and Flag Example
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/api/definitions.md
Demonstrates different ways attributes can be quoted (double, single) and the presence of flag attributes (unquoted) within an HTML paragraph tag, used to identify quote types.
```html
Hello, World!
```
--------------------------------
### Dynamically Generate HTML Table with simple_html_dom in PHP
Source: https://github.com/datanfr/datan/blob/master/scripts/lib/simplehtmldom_1_9/manual/docs/manual/adding-nodes.md
This PHP example demonstrates how to create new HTML elements and append them to an existing DOM structure using the `simple_html_dom` library. It specifically shows how to build a table from an array of data, including creating table, row, header, and data cells, and setting attributes. The script initializes an HTML document, populates a table with ocean volume data, and then appends the generated table to the document's body.
```php
Volumes of the World's Oceans