-
Notifications
You must be signed in to change notification settings - Fork 20
CSS Selectors
Thomas Weinert edited this page Jul 8, 2015
·
6 revisions
Optionally you can use CSS selectors with FluentDOM\Query and FluentDOM\Document/FluentDOM\Element (FluentDOM >= 5.3 only).
FluentDOM <= 5.2 can use Symfony CSS Selectors or PhpCss. With version 5.3 an interface and connector packages were added. The connectors use a library to parse the CSS selector and convert it into an Xpath expression.
This static function of the FluentDOM class returns an instance of FluentDOM\Query. It allows to use CSS selectors as arguments that are expected to be an selector string.
$result = \FluentDOM::QueryCss($html, 'text/html')
->find('p')
->find('span')
->filter('.mark')
->addClass('red');FluentDOM\Document and FluentDOM\Element support the Selectors API Level 1. You can use querySelector() and querySelectorAll().
$document = new FluentDOM\Document();
$document->loadHTML($html);
foreach ($document->querySelectorAll('li') as $li) {
var_dump((string)$li);
}
var_dump(
$document->querySelector('ul li:nth-child(2)')->textContent
);- Home
- Getting Started
- Tasks
- Plugins
- Functions
- Lists
- Creator (5.1)
- CSS Selectors
- Convertors
- Loaders
- Serializers (5.1)
- Transformers (5.1)
- Extended DOM
- XMLReader (6.1)
- XMLWriter (6.1)
- Interfaces