carica/phpcss
Composer 安装命令:
composer require carica/phpcss
包简介
An css selector parser and converter
README 文档
README
- License: The MIT License
- Copyright: 2010-2018 PhpCss Team
- Author: Thomas Weinert thomas@weinert.info
Thanks to Benjamin Eberlei, Bastian Feder and Jakob Westhoff for ideas and concepts.
PhpCSS is a parser for CSS 3 selectors. It parses them into an AST and allows them to compile the AST to CSS selectors or Xpath expressions.
The main target of this project is the possibilty to convert CSS selectors into Xpath expressions.
Demo
A small demo application can be found at: http://xpath.thomas.weinert.info/
Installation
PhpCss is available on Packagist: Carica/PhpCss. Add it to you composer.json and update.
Basic Usage
Get CSS selector as Xpath expression
$expression = PhpCss::toXpath($selector);
Reformat/Validate CSS Selector
$selector = PhpCss::reformat($selector);
Get the AST
$ast = PhpCss::getAst($selector);
FluentDOM
FluentDOM 5 allows to inject a callback to convert selectors. If you have FluentDOM and PhpCss installed in your project, you can use CSS selectors in FluentDOM:
$fd = FluentDOM::QueryCss($xml);
$fd
->find('td:nth-of-type(even)')
->addClass('even');
Supported
| Selector | to CSS | to Xpath |
|---|---|---|
| * | ✓ | ✓ |
| E | ✓ | ✓ |
| ns|* | ✓ | ✓ |
| ns|E | ✓ | ✓ |
| Attributes | ||
| E[foo] | ✓ | ✓ |
| E[foo="bar"] | ✓ | ✓ |
| E[foo~="bar"] | ✓ | ✓ |
| E[foo^="bar"] | ✓ | ✓ |
| E[foo$="bar"] | ✓ | ✓ |
| E[foo*="bar"] | ✓ | ✓ |
| E[foo|="bar"] | ✓ | ✓ |
| Structural Pseudo Classes | ||
| E:root | ✓ | ✓ |
| E:nth-child(42) | ✓ | ✓ |
| E:nth-last-child(42) | ✓ | ✓ |
| E:nth-of-type(42) | ✓ | ✓ |
| E:nth-last-of-type(42) | ✓ | ✓ |
| E:first-child | ✓ | ✓ |
| E:last-child | ✓ | ✓ |
| E:first-of-type | ✓ | ✓ |
| E:last-of-type | ✓ | ✓ |
| E:only-child | ✓ | ✓ |
| E:only-of-type | ✓ | ✓ |
| E:empty | ✓ | ✓ |
| Link Pseudo Classes | ||
| E:link | ✓ | ✗ |
| E:visited | ✓ | ✗ |
| User Action Pseudo Classes | ||
| E:active | ✓ | ✗ |
| E:hover | ✓ | ✗ |
| E:focus | ✓ | ✗ |
| Target Pseudo Class | ||
| E:target | ✓ | ✗ |
| Language Pseudo Class | ||
| E:lang(fr) | ✓ | ✓ |
| UI Element states Pseudo Class | ||
| E:enabled | ✓ | ✓ (not disabled) |
| E:disabled | ✓ | ✓ (attribute) |
| E:checked | ✓ | ✓ (attribute) |
| Pseudo Elements | ||
| E:first-line | ✓ | ✗ |
| E:first-letter | ✓ | ✗ |
| E:before | ✓ | ✗ |
| E:after | ✓ | ✗ |
| Class Selector | ||
| E.warning | ✓ | ✓ |
| Id Selector | ||
| E#myid | ✓ | ✓ |
| Negation Pseudo Class | ||
| E:not(s) | ✓ | ✓ |
| Combinators | ||
| E F | ✓ | ✓ |
| E > F | ✓ | ✓ |
| E + F | ✓ | ✓ |
| E ~ F | ✓ | ✓ |
| jQuery | ||
| :contains("text") | ✓ | ✓ |
| :has(s) | ✓ | ✓ |
| :gt(42) | ✓ | ✓ |
| :lt(42) | ✓ | ✓ |
| :odd | ✓ | ✓ |
| :even | ✓ | ✓ |
carica/phpcss 适用场景与选型建议
carica/phpcss 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 72.46k 次下载、GitHub Stars 达 72, 最近一次更新时间为 2014 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 carica/phpcss 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 carica/phpcss 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 72.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 74
- 点击次数: 18
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-02-14