phpgt/cssxpath 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpgt/cssxpath

最新稳定版本:v1.4.0

Composer 安装命令:

composer require phpgt/cssxpath

包简介

Convert CSS selectors to XPath queries.

README 文档

README

A lightweight and dependency free CSS to XPath translator. This repository is used to bring modern DOM functionality like querySelectorAll() to PHP in the PHP.Gt/Dom project.

Build status Code quality Code coverage Current version PHP.Gt/CssXPath documentation

Example usage

use Gt\CssXPath\Translator;

$html = <<<HTML
<form>
	<label>
		Name
		<input name="name" />
	</label>
	<label>
		Code:
		<input name="code" />
	</label>
	<button name="do" value="submit">Submit code</button>
</form>
HTML;

$document = new DOMDocument();
$document->loadHTML($html);

$xpath = new DOMXPath($document);
$inputElementList = $xpath->query(new Translator("form>label>input");

Using this library with XML Documents

To correctly work with XML documents, where the attributes are case-sensitive, pass false to the htmlMode property of the constructor.

$translator = new Translator("[data-FOO='bar']", htmlMode: false);

It's perhaps worth noting that for XML-style matching to work, you must load the document content with DOMDocument->load/DOMDocument->loadXML instead of DOMDocument->loadHTMLFile/DOMDocument->loadHTML, as the HTML loading methods automatically convert the tags and attribute names to lowercase. This is handled automatically when using PHP.Gt/Dom.

Proudly sponsored by

JetBrains Open Source sponsorship program

JetBrains logo.

统计信息

  • 总下载量: 11.49M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 3
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04