Skip to content

Commit 1927d92

Browse files
committed
Update options method names
1 parent 4e01a43 commit 1927d92

File tree

1 file changed

+35
-45
lines changed

1 file changed

+35
-45
lines changed

README.md

+35-45
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
PHP Html Parser
2-
==========================
1+
# PHP Html Parser
32

43
[![Build Status](https://travis-ci.org/paquettg/php-html-parser.png)](https://travis-ci.org/paquettg/php-html-parser)
54
[![Coverage Status](https://coveralls.io/repos/paquettg/php-html-parser/badge.png)](https://coveralls.io/r/paquettg/php-html-parser)
65
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/paquettg/php-html-parser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/paquettg/php-html-parser/?branch=master)
76

87
PHPHtmlParser is a simple, flexible, html parser which allows you to select tags using any css selector, like jQuery. The goal is to assist in the development of tools which require a quick, easy way to scrap html, whether it's valid or not!
98

10-
Install
11-
-------
9+
## Install
1210

1311
Install the latest version using composer.
1412

@@ -18,8 +16,7 @@ $ composer require paquettg/php-html-parser
1816

1917
This package can be found on [packagist](https://packagist.org/packages/paquettg/php-html-parser) and is best loaded using [composer](http://getcomposer.org/). We support php 7.2, 7.3, and 7.4.
2018

21-
Basic Usage
22-
-----
19+
## Basic Usage
2320

2421
You can find many examples of how to use the DOM parser and any of its parts (which you will most likely never touch) in the tests directory. The tests are done using PHPUnit and are very small, a few lines each, and are a great place to start. Given that, I'll still be showing a few examples of how the package should be used. The following example is a very simplistic usage of the package.
2522

@@ -36,15 +33,13 @@ echo $a->text; // "click here"
3633

3734
The above will output "click here". Simple, no? There are many ways to get the same result from the DOM, such as `$dom->getElementsbyTag('a')[0]` or `$dom->find('a', 0)`, which can all be found in the tests or in the code itself.
3835

39-
Support PHP Html Parser Financially
40-
--------------
36+
## Support PHP Html Parser Financially
4137

4238
Get supported Monolog and help fund the project with the [Tidelift Subscription](https://tidelift.com/subscription/pkg/packagist-paquettg-php-html-parser?utm_source=packagist-paquettg-php-html-parser&utm_medium=referral&utm_campaign=enterprise).
4339

4440
Tidelift delivers commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.
4541

46-
Loading Files
47-
------------------
42+
## Loading Files
4843

4944
You may also seamlessly load a file into the DOM instead of a string, which is much more convenient and is how I expect most developers will be loading the HTML. The following example is taken from our test and uses the "big.html" file found there.
5045

@@ -62,7 +57,7 @@ foreach ($contents as $content)
6257
{
6358
// get the class attr
6459
$class = $content->getAttribute('class');
65-
60+
6661
// do something with the html
6762
$html = $content->innerHtml;
6863

@@ -74,10 +69,9 @@ foreach ($contents as $content)
7469

7570
This example loads the html from big.html, a real page found online, and gets all the content-border classes to process. It also shows a few things you can do with a node but it is not an exhaustive list of the methods that a node has available.
7671

77-
Loading URLs
78-
----------------
72+
## Loading URLs
7973

80-
Loading a URL is very similar to the way you would load the HTML from a file.
74+
Loading a URL is very similar to the way you would load the HTML from a file.
8175

8276
```php
8377
// Assuming you installed from Composer:
@@ -108,8 +102,7 @@ $html = $dom->outerHtml;
108102

109103
As long as the client object implements the interface properly, it will use that object to get the content of the url.
110104

111-
Loading Strings
112-
---------------
105+
## Loading Strings
113106

114107
Loading a string directly is also easily done.
115108

@@ -123,8 +116,7 @@ $dom->loadStr('<html>String</html>');
123116
$html = $dom->outerHtml;
124117
```
125118

126-
Options
127-
-------
119+
## Options
128120

129121
You can also set parsing option that will effect the behavior of the parsing engine. You can set a global option array using the `setOptions` method in the `Dom` object or a instance specific option by adding it to the `load` method as an extra (optional) parameter.
130122

@@ -141,7 +133,7 @@ $dom->setOptions(
141133
->setStrict(true)
142134
);
143135

144-
$dom->loadFromUrl('http://google.com',
136+
$dom->loadFromUrl('http://google.com',
145137
(new Options())->setWhitespaceTextNode(false) // only applies to this load.
146138
);
147139

@@ -150,56 +142,55 @@ $dom->loadFromUrl('http://gmail.com'); // will not have whitespaceTextNode set t
150142

151143
At the moment we support 12 options.
152144

153-
**Strict**
145+
**setStrict**
154146

155-
Strict, by default false, will throw a `StrickException` if it find that the html is not strictly compliant (all tags must have a closing tag, no attribute with out a value, etc.).
147+
`setStrict`, by default `false`, will throw a `StrickException` if it find that the html is not strictly compliant (all tags must have a closing tag, no attribute with out a value, etc.).
156148

157-
**whitespaceTextNode**
149+
**setWhitespaceTextNode**
158150

159-
The whitespaceTextNode, by default true, option tells the parser to save textnodes even if the content of the node is empty (only whitespace). Setting it to false will ignore all whitespace only text node found in the document.
151+
The `setWhitespaceTextNode`, by default `true`, option tells the parser to save textnodes even if the content of the node is empty (only whitespace). Setting it to `false` will ignore all whitespace only text node found in the document.
160152

161-
**enforceEncoding**
153+
**setEnforceEncoding**
162154

163-
The enforceEncoding, by default null, option will enforce an character set to be used for reading the content and returning the content in that encoding. Setting it to null will trigger an attempt to figure out the encoding from within the content of the string given instead.
155+
The `setEnforceEncoding`, by default `null`, option will enforce an character set to be used for reading the content and returning the content in that encoding. Setting it to `null` will trigger an attempt to figure out the encoding from within the content of the string given instead.
164156

165-
**cleanupInput**
157+
**setCleanupInput**
166158

167-
Set this to `false` to skip the entire clean up phase of the parser. If this is set to true the next 3 options will be ignored. Defaults to `true`.
159+
Set `setCleanupInput` to `false` to skip the entire clean up phase of the parser. If this is set to true the next 3 options will be ignored. Defaults to `true`.
168160

169-
**removeScripts**
161+
**setRemoveScripts**
170162

171-
Set this to `false` to skip removing the script tags from the document body. This might have adverse effects. Defaults to `true`.
163+
Set `setRemoveScripts` to `false` to skip removing the script tags from the document body. This might have adverse effects. Defaults to `true`.
172164

173-
**removeStyles**
165+
**setRemoveStyles**
174166

175-
Set this to `false` to skip removing of style tags from the document body. This might have adverse effects. Defaults to `true`.
167+
Set `setRemoveStyles` to `false` to skip removing of style tags from the document body. This might have adverse effects. Defaults to `true`.
176168

177-
**preserveLineBreaks**
169+
**setPreserveLineBreaks**
178170

179-
Preserves Line Breaks if set to `true`. If set to `false` line breaks are cleaned up as part of the input clean up process. Defaults to `false`.
171+
`setPreserveLineBreaks` preserves line Breaks if set to `true`. If set to `false` line breaks are cleaned up as part of the input clean up process. Defaults to `false`.
180172

181-
**removeDoubleSpace**
173+
**setRemoveDoubleSpace**
182174

183-
Set this to `false` if you want to preserve whitespace inside of text nodes. It is set to `true` by default.
175+
Set `setRemoveDoubleSpace` to `false` if you want to preserve whitespace inside of text nodes. It is set to `true` by default.
184176

185-
**removeSmartyScripts**
177+
**setRemoveSmartyScripts**
186178

187-
Set this to `false` if you want to preserve smarty script found in the html content. It is set to `true` by default.
179+
Set `setRemoveSmartyScripts` to `false` if you want to preserve smarty script found in the html content. It is set to `true` by default.
188180

189-
**htmlSpecialCharsDecode**
181+
**setHtmlSpecialCharsDecode**
190182

191-
By default this is set to `false`. Setting this to `true` will apply the php function `htmlspecialchars_decode` too all attribute values and text nodes.
183+
By default `setHtmlSpecialCharsDecode` is set to `false`. Setting this to `true` will apply the php function `htmlspecialchars_decode` too all attribute values and text nodes.
192184

193-
**selfClosing**
185+
**setSelfClosing**
194186

195187
This option contains an array of all self closing tags. These tags must be self closing and the parser will force them to be so if you have strict turned on. You can update this list with any additional tags that can be used as a self closing tag when using strict. You can also remove tags from this array or clear it out completly.
196188

197-
**noSlash**
189+
**setNoSlash**
198190

199191
This option contains an array of all tags that can not be self closing. The list starts off as empty but you can add elements as you wish.
200192

201-
Static Facade
202-
-------------
193+
## Static Facade
203194

204195
You can also mount a static facade for the Dom object.
205196

@@ -213,8 +204,7 @@ $objects = Dom::find('.content-border');
213204

214205
The above php block does the same find and load as the first example but it is done using the static facade, which supports all public methods found in the Dom object.
215206

216-
Modifying The Dom
217-
-----------------
207+
## Modifying The Dom
218208

219209
You can always modify the dom that was created from any loading method. To change the attribute of any node you can just call the `setAttribute` method.
220210

0 commit comments

Comments
 (0)