-
Notifications
You must be signed in to change notification settings - Fork 20
CSS Selectors
Thomas Weinert edited this page Jul 12, 2018
·
6 revisions
FluentDOM uses an interface and connector package were to add CSS selector support. The connectors use a library to parse the CSS selector and convert it into an Xpath expression.
Connector packages:
After you install them you can use CSS selectors.
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\DOM\Document, FluentDOM\DOM\Element, FluentDOM\DOM\DocumentFragment support the Selectors API Level 1. You can use querySelector() and querySelectorAll().
$document = new FluentDOM\DOM\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