Skip to content

Commit 90c21c9

Browse files
committed
update readme with more details on how to use settings
1 parent cd0f834 commit 90c21c9

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ Add php-css-parser to your composer.json
1919

2020
To use the CSS Parser, create a new instance. The constructor takes the following form:
2121

22-
$oSettings = Sabberworm\CSS\Settings::create()->withDefaultCharset('utf-8');
23-
new Sabberworm\CSS\Parser($sText, $oSettings);
24-
25-
The charset is used only if no @charset declaration is found in the CSS file. UTF-8 is the default, so you won’t have to create a settings object at all if you don’t intend to change that.
22+
new Sabberworm\CSS\Parser($sText);
2623

2724
To read a file, for example, you’d do the following:
2825

@@ -31,12 +28,28 @@ To read a file, for example, you’d do the following:
3128

3229
The resulting CSS document structure can be manipulated prior to being output.
3330

34-
### Strict parsing
31+
### Options
32+
33+
#### Charset
34+
35+
The charset option is used only if no @charset declaration is found in the CSS file. UTF-8 is the default, so you won’t have to create a settings object at all if you don’t intend to change that.
36+
37+
$oSettings = Sabberworm\CSS\Settings::create()->withDefaultCharset('windows-1252');
38+
new Sabberworm\CSS\Parser($sText, $oSettings);
3539

36-
To have the parser choke on invalid rules, supply a Sabberworm\CSS\Settings object:
40+
#### Strict parsing
41+
42+
To have the parser choke on invalid rules, supply a thusly configured Sabberworm\CSS\Settings object:
3743

3844
$oCssParser = new Sabberworm\CSS\Parser(file_get_contents('somefile.css'), Sabberworm\CSS\Settings::create()->beStrict());
3945

46+
#### Disable multibyte functions
47+
48+
To achieve faster parsing, you can choose to have PHP-CSS-Parser use regular string functions instead of `mb_*` functions. This should work fine in most cases, even for UTF-8 files, as all the multibyte characters are in string literals. Still it’s not recommended to use this with input you have no control over as it’s not thoroughly covered by test cases.
49+
50+
$oSettings = Sabberworm\CSS\Settings::create()->withMultibyteSupport(false);
51+
new Sabberworm\CSS\Parser($sText, $oSettings);
52+
4053
### Manipulation
4154

4255
The resulting data structure consists mainly of five basic types: `CSSList`, `RuleSet`, `Rule`, `Selector` and `Value`. There are two additional types used: `Import` and `Charset` which you won’t use often.

0 commit comments

Comments
 (0)