Skip to content

Commit 849b61e

Browse files
committed
Fixed bug in htmldoc::key() where the wrong return type was specified.
Fixed issues in documentation. Added more tests to findHtmldocTest::testCanTraverseElements() to test traversing as an array.
1 parent 0ca9fe9 commit 849b61e

File tree

7 files changed

+42
-19
lines changed

7 files changed

+42
-19
lines changed

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/html.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ if ($doc->load($html)) {
1313

1414
<table>
1515
<thead>
16-
<th>Parameter</th>
17-
<th>Type</th>
18-
<th>Options</th>
19-
<th>Description</th>
20-
<th>Default</th>
16+
<tr>
17+
<th>Parameter</th>
18+
<th>Type</th>
19+
<th>Options</th>
20+
<th>Description</th>
21+
<th>Default</th>
22+
</tr>
2123
</thead>
2224
<tbody>
2325
<tr>

docs/api/load.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ $doc->load($html, $charset = null);
1414
| `$html` | String | The HTML to be parsed into the object |
1515
| `$charset`| String | The charset of the document, or `null` to auto-detect |
1616

17+
## Auto-detecting the Charset
18+
19+
If `$charset` is set to null, the program will attempt to auto-detect the charset by looking for:
20+
21+
`<meta http-equiv="Content-Type" content="text/html; charset=xxx" />`
22+
23+
Where the charset will be extracted from, otherwise the charset will be detected using `mb_detect_encoding`.
24+
1725
## Returns
1826

1927
A boolean indicating whether the HTML was parsed successfully.

docs/api/minify.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ An optional array contains a list of configuration parameters to configure the m
1717

1818
<table>
1919
<thead>
20-
<th>Parameter</th>
21-
<th>Type</th>
22-
<th>Options</th>
23-
<th>Description</th>
24-
<th>Default</th>
20+
<tr>
21+
<th>Parameter</th>
22+
<th>Type</th>
23+
<th>Options</th>
24+
<th>Description</th>
25+
<th>Default</th>
26+
</tr>
2527
</thead>
2628
<tbody>
2729
<tr>

docs/api/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ This document describes how to configure and use the HTMLdoc object.
55
| Method | Description |
66
|-----------------------------------|-------------------------------------------|
77
| [__construct()](construct.md) | Constructs an HTMLdoc object |
8-
| [open()](open.md) | Open an HTML file from a URL or stream |
9-
| [load()](load.md) | Load HTML from a strings |
8+
| [open()](open.md) | Open an HTML document from a URL or stream |
9+
| [load()](load.md) | Load HTML from a string |
1010
| [find()](find.md) | Find elements within the documents |
1111
| [eq()](eq.md) | Filter elements to the selected index |
1212
| [first()](first.md) | Filter elements by the first element |
1313
| [last()](last.md) | Filter elements by the last element |
1414
| [attr()](attr.md) | Retrieve the value of an attribute |
1515
| [text()](text.md) | Extract text from an HTMLdoc |
1616
| [minify()](minify.md) | Minify the HTMLdoc |
17-
| [html()](html.md) | Render the document as HTMLdoc |
17+
| [html()](html.md) | Render the document as HTML |
1818
| [save()](save.md) | Save as a file or output as a string |

src/htmldoc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function current() {
134134
*
135135
* @return scalar The current pointer position
136136
*/
137-
public function key() : scalar {
137+
public function key() : int {
138138
return $this->pointer;
139139
}
140140

tests/findHtmldocTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ public function testCanTraverseElements() {
6060
$this->assertEquals(3, count($doc->find('body > *')->get()));
6161
$this->assertEquals('<div class="last">Last</div>', $doc->find('body > *')->get(2)->html());
6262
$this->assertEquals('<div class="last">Last</div>', $doc->find('body > *')->get(-1)->html());
63+
64+
$cls = ['first', 'find', 'last'];
65+
$divs = $doc->find('body > *');
66+
$this->assertTrue(isset($divs[0]), true);
67+
$this->assertEquals($cls[0], $divs[0]->attr('class'));
68+
foreach ($divs AS $key => $item) {
69+
$this->assertEquals($cls[$key], $item->attr('class'));
70+
}
71+
72+
unset($divs[2]);
73+
$this->assertEquals(isset($divs[2]), false);
6374
}
6475
}
6576

0 commit comments

Comments
 (0)