Skip to content

Commit 136fc51

Browse files
Update README.md
1 parent ec9f06d commit 136fc51

1 file changed

Lines changed: 147 additions & 0 deletions

File tree

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,150 @@ $doc->echo();
388388
<p id="1">1</p>
389389
</div>
390390
```
391+
392+
## `hasClass` and `hasAttr`
393+
394+
These functions are built to test if an element has a specific class/attribute or not. If it does, it returns true.
395+
396+
### `$html`
397+
398+
```html
399+
<p class="rice">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
400+
<p data-target="lord">Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
401+
```
402+
403+
### Php
404+
405+
```php
406+
include "path/webscraper.php";
407+
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
408+
409+
if ($doc->Q("p[1]")->hasClass("rice")) {
410+
echo "p[1] has class \"rice\": true \n\n";
411+
}
412+
413+
if ($doc->Q("p[2]")->hasAttr("data-target", "lady")) {
414+
echo "p[2] has attribute \"data-target\" with value \"lady\": false";
415+
}
416+
417+
$doc->echo();
418+
```
419+
### Output
420+
421+
```html
422+
p[1] has class "rice": true
423+
424+
p[2] has attribute "data-target" with value "lady": false
425+
```
426+
427+
## `delete`
428+
429+
The delete function is used to delete DOM nodes.
430+
It accepts a boolean as a parameter: `true` or `false`, `true` tells it to keep its inner content (be it text or html nodes), while `false` tells it the opposite. The default parameter is set to `true`.
431+
432+
### `$html`
433+
434+
```html
435+
<head>
436+
<style>
437+
code {
438+
font-family: Consolas,"courier new";
439+
color: crimson;
440+
background-color: #f1f1f1;
441+
padding: 2px;
442+
font-size: 105%;
443+
}
444+
</style>
445+
</head>
446+
<body>
447+
448+
<p>The HTML <code>button</code> tag defines a clickable button.</p>
449+
<p>The CSS <code>background-color</code> property defines the background color of an element.</p>
450+
451+
</body>
452+
```
453+
454+
### Php
455+
456+
```php
457+
include "path/webscraper.php";
458+
$doc = new WebScraper("<!DOCTYPE html><html>".$html."</html>");
459+
460+
$doc->Q("style")->delete();
461+
462+
$doc->echo();
463+
```
464+
### Output
465+
466+
```html
467+
<head>
468+
</head>
469+
<body>
470+
471+
<p>The HTML <code>button</code> tag defines a clickable button.</p>
472+
<p>The CSS <code>background-color</code> property defines the background color of an element.</p>
473+
474+
</body>
475+
```
476+
In the other hand...
477+
478+
```php
479+
include "path/webscraper.php";
480+
$doc = new WebScraper("<!DOCTYPE html><html>".$html."</html>");
481+
482+
$doc->Q("p")->delete(true);
483+
484+
$doc->echo();
485+
```
486+
487+
Will output
488+
489+
```html
490+
<head>
491+
</head>
492+
<body>
493+
494+
The HTML <code>button</code> tag defines a clickable button.
495+
The CSS <code>background-color</code> property defines the background color of an element.
496+
497+
</body>
498+
```
499+
500+
501+
## `iterate` and `replaceText`
502+
503+
These functions are built to test if an element has a specific class/attribute or not. If it does, it returns true.
504+
505+
### `$html`
506+
507+
```html
508+
<p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia.</p>
509+
510+
<p>It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar.</p>
511+
512+
<p>The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then</p>
513+
```
514+
515+
### Php
516+
517+
```php
518+
include "path/webscraper.php";
519+
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
520+
521+
if ($doc->Q("p[1]")->hasClass("rice")) {
522+
echo "p[1] has class \"rice\": true \n\n";
523+
}
524+
525+
if ($doc->Q("p[2]")->hasAttr("data-target", "lady")) {
526+
echo "p[2] has attribute \"data-target\" with value \"lady\": false";
527+
}
528+
529+
$doc->echo();
530+
```
531+
### Output
532+
533+
```html
534+
p[1] has class "rice": true
535+
536+
p[2] has attribute "data-target" with value "lady": false
537+
```

0 commit comments

Comments
 (0)