Skip to content

Commit 47a0773

Browse files
committed
Update README.md
1 parent 830ab98 commit 47a0773

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,35 @@ See [tests/README.md](https://github.com/duzun/hQuery.php/blob/master/tests/READ
2626
- PHP 5.3+
2727
- No dependencies
2828

29+
## Requirements
30+
31+
- PHP 5.3 or newer (PHP 7.4+ recommended)
32+
- `mbstring` extension is recommended for reliable charset handling and conversions
33+
- Ensure a sufficient `memory_limit` when working with very large documents
34+
2935
## 🛠 Install
3036

31-
Just add this folder to your project and `include_once 'hquery.php';` and you are ready to `hQuery`.
37+
Add the library to your project and include it, or install via Composer/npm.
38+
39+
Using Composer (recommended):
40+
41+
```sh
42+
composer require duzun/hquery
43+
```
3244

33-
Alternatively `composer require duzun/hquery`
45+
Or include manually:
3446

35-
or using `npm install hquery.php`, `require_once 'node_modules/hquery.php/hquery.php';`.
47+
```php
48+
include_once '/path/to/hquery.php/hquery.php';
49+
```
50+
51+
Or via npm:
52+
53+
```sh
54+
npm install hquery.php
55+
```
56+
57+
Then require the file from `node_modules` if needed.
3658

3759
## ⚙ Usage
3860

@@ -160,19 +182,19 @@ $titles = array();
160182
if ( $banners ) {
161183

162184
// Iterate over the result
163-
foreach($banners as $pos => $a) {
185+
foreach($banners as $id => $a) {
164186
// $a->href property is the resolved $a->attr('href') relative to the
165187
// documents <base href=...>, if present, or $doc->baseURL.
166-
$links[$pos] = $a->href; // get absolute URL from href property
167-
$titles[$pos] = trim($a->text()); // strip all HTML tags and leave just text
188+
$links[$id] = $a->href; // get absolute URL from href property
189+
$titles[$id] = trim($a->text()); // strip all HTML tags and leave just text
168190

169191
// Filter the result
170192
if ( !$a->hasClass('logo') ) {
171193
// $a->style property is the parsed $a->attr('style'), same as $a->attr('style', true)
172194
if ( strtolower($a->style['position']) == 'fixed' ) continue;
173195

174196
$img = $a->find('img')[0]; // ArrayAccess
175-
if ( $img ) $images[$pos] = $img->src; // short for $img->attr('src', true)
197+
if ( $img ) $images[$id] = $img->src; // short for $img->attr('src', true)
176198
}
177199
}
178200

@@ -201,7 +223,12 @@ $requestUri = $doc->href;
201223
$baseURL = $doc->baseURL;
202224
```
203225

204-
Note: In case the charset meta attribute has a wrong value or the internal conversion fails for any other reason, `hQuery` would ignore the error and continue processing with the original HTML, but would register an error message on `$doc->html_errors['convert_encoding']`.
226+
Charset and positions:
227+
228+
- The document is converted internally to UTF-8 for parsing.
229+
- Element positions (the numeric offsets used internally and returned by APIs that expose byte offsets) refer to the internal UTF-8 string bytes.
230+
231+
Note: In case the charset meta attribute has a wrong value or the internal conversion fails for any other reason, `hQuery` will continue processing with the original HTML, but will register an error message on `$doc->html_errors['convert_encoding']`.
205232

206233
## 🖧 Live Demo
207234

0 commit comments

Comments
 (0)