Register PHP functions as XPath functions. Works like `\DOMXPath::registerPhpFunctions` except that the php namespace does not need to be registered.
* `restrict`: Use this parameter to only allow certain functions to be called from XPath. This parameter can be either a string (a function name), an array of function names, or null to allow everything.
##### Example #####
```php
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html><body><h1>Ook</h1><pclass="subtitle1">Eek?</p><pclass="subtitle2">Ook?</p></body></html>');
echo "Found " . count($result) . " nodes with classes starting with 'subtitle':\n";
foreach ($result as $node) {
echo "$node\n";
}
```
Output:
```
Found 2 nodes with classes starting with 'subtitle':
<pclass="subtitle1">Eek?</p>
<pclass="subtitle2">Ook?</p>
```
#### MensBeam\HTML\DOM\Document::serialize ####
#### MensBeam\HTML\DOM\Document::serialize ####
Converts a node to a string.
Converts a node to a string.
@ -52,6 +114,56 @@ Converts a node to a string.
- `indentWithSpaces` (`bool|null`): Whether to use spaces or tabs to indent. This is `true` by default and has no effect unless `reformatWhitespace` is `true`
- `indentWithSpaces` (`bool|null`): Whether to use spaces or tabs to indent. This is `true` by default and has no effect unless `reformatWhitespace` is `true`
- `reformatWhitespace` (`bool|null`): Whether to reformat whitespace (pretty-print) or not. This is `false` by default
- `reformatWhitespace` (`bool|null`): Whether to reformat whitespace (pretty-print) or not. This is `false` by default
##### Examples #####
- Serializing a document:
```php
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html></html>');
echo $d->serialize();
```
or:
```php
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html></html>');
Register PHP functions as XPath functions. Works like `\DOMXPath::registerPhpFunctions` except that the php namespace does not need to be registered.
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html></html>');
* `document`: The document to register the functions on.
echo $d->serialize();
* `restrict`: Use this parameter to only allow certain functions to be called from XPath. This parameter can be either a string (a function name), an array of function names, or null to allow everything.
```
or:
### MensBeam\HTML\DOM\XPathResult ###
```php
`MensBeam\HTML\DOM\XPathResult` implements `\ArrayAccess`, `\Countable`, and `\Iterator` and will allow for accessing as if it is an array when the result type is `MensBeam\HTML\DOM\XPathResult::ORDERED_NODE_ITERATOR_TYPE`, `MensBeam\HTML\DOM\XPathResult::UNORDERED_NODE_ITERATOR_TYPE`, `MensBeam\HTML\DOM\XPathResult::ORDERED_NODE_SNAPSHOT_TYPE`, or `MensBeam\HTML\DOM\XPathResult::UNORDERED_NODE_SNAPSHOT_TYPE`.
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html></html>');
```php
echo $d;
partial class XPathResult implements \ArrayAccess, \Countable, \Iterator {
```
}
```
- Serializing a document (pretty printing):
```php
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html></html>');