felipe1234-dev/php-dom-query

易于学习的 PHP DOM 解析器,具有 CSS 选择器和简写代码

v1.0 2020-12-21 06:50 UTC

This package is not auto-updated.

Last update: 2024-09-27 15:26:36 UTC


README

易于学习的 PHP DOM 解析器,具有 CSS 选择器、简写代码和操作文本节点的能力

GitHub issues GitHub forks GitHub stars GitHub license

简单的 PHP Dom Query 接口简化了原生的 PHP Dom Document,使其尽可能接近 jQuery,以便前端开发者易于使用。在这个库中,jQuery 和类似 jQuery 的 PHP DOM 的大多数主要功能的行为和语法都完全一样。这个库是为了培训目的而制作的。

安装

Composer

composer require felipe1234-dev/php-dom-query

Git

git clone git://git.code.sf.net/p/jquery-like-php-dom/repository jquery-like-php-dom

类似 jQuery 的 PHP DOM 与 jQuery 的比较

包装元素

jQuery

<script>
$(document).ready(function(){
   $("img").wrap("<figure></figure>");
});
</script>

类似 jQuery 的 PHP DOM

<?php 
include "path/webparser.php";
$doc = new WebParser();
$doc->loadHTMLFile($url);

$doc->Q("img")->wrap("<figure></figure>");

$doc->output();
?>
添加 HTML

jQuery

<script>
$(document).ready(function(){
  $("ol").append("<li>Appended item</li>");
});
</script>

类似 jQuery 的 PHP DOM

include "path/webparser.php";
$doc = new WebParser();
$doc->loadHTMLFile($url);

$doc->Q("ol")->append("<li>Appended item</li>");

$doc->output();
更改第一个 <a> 的 href

jQuery

<script>
$(document).ready(function(){
  $("a:first").href("folder/index.html");
});
</script>

类似 jQuery 的 PHP DOM

include "path/webparser.php";
$doc = new WebParser();
$doc->loadHTMLFile($url);

$doc->Q("a:first")->href("folder/index.html");

$doc->output();

有关更多示例和用法,请参阅 手册 下的安装文件夹。

发布历史

  • v1.0
    • 更改:初始发布,准备使用

元数据

费利佩·阿尔维斯 – felipejean2002@gmail.com

在 MIT 许可下分发。有关更多信息,请参阅 LICENSE

https://github.com/felipe1234-dev/github-link

贡献

  1. 分叉它 (https://github.com/felipe1234-dev/jquery-like-php-dom/fork)
  2. 创建您的功能分支 (git checkout -b feature/jquery-like-php-dom)
  3. 提交您的更改 (git commit -am '添加一些描述')
  4. 推送到分支 (git push origin feature/jquery-like-php-dom)
  5. 创建一个新的 Pull Request