Skip to content

Navigation Menu

Sign up

Getting Started: 5. CSS Queries

Daniele Orlando edited this page Feb 21, 2016 · 4 revisions

XPath is very powerful but CSS Selectors are more concise sometimes.

Concise syntax

$eggs = $food('egg');
$fruits = $food('fruit[price="expensive"');
> Extended syntax
> ```php
> $eggs = $food->query('egg');
> $fruits = $food->query('fruit[price="expensive"]');

Pro Tip:
Like for XPath, query() supports a variable number of CSS queries. In addition, XPaths and CSS Selectors can be mixed in the same query.

$food('//title', 'chapters > chapter');

The supported CSS selectors are:

  • #id
  • .class
  • E[attr="val"]
  • *
  • :root
  • namespace|E
  • E E
  • E > E
  • E + E
  • E ~ E
  • E , E

Note:
Remember that CSS selectors are translated internally to XPath and this operation adds some overhead. If you need the best performances possible, go with XPath.

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /