{"id":42437054,"url":"https://github.com/xinningsu/html-query","last_synced_at":"2026-01-28T05:44:16.423Z","repository":{"id":57084395,"uuid":"193344794","full_name":"xinningsu/html-query","owner":"xinningsu","description":"A jQuery-like html processor written in PHP","archived":false,"fork":false,"pushed_at":"2025-08-07T07:17:00.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-07T09:15:41.538Z","etag":null,"topics":["html-processor","html-query","php-jquery"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xinningsu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-23T12:22:27.000Z","updated_at":"2025-08-07T07:17:03.000Z","dependencies_parsed_at":"2022-08-25T00:50:12.848Z","dependency_job_id":null,"html_url":"https://github.com/xinningsu/html-query","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/xinningsu/html-query","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinningsu%2Fhtml-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinningsu%2Fhtml-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinningsu%2Fhtml-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinningsu%2Fhtml-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xinningsu","download_url":"https://codeload.github.com/xinningsu/html-query/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinningsu%2Fhtml-query/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28840156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T05:41:00.775Z","status":"ssl_error","status_checked_at":"2026-01-28T05:40:47.726Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html-processor","html-query","php-jquery"],"created_at":"2026-01-28T05:44:15.908Z","updated_at":"2026-01-28T05:44:16.419Z","avatar_url":"https://github.com/xinningsu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html-query\n\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![Build Status](https://scrutinizer-ci.com/g/xinningsu/html-query/badges/build.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/html-query/build-status/master)\n[![Code Coverage](https://scrutinizer-ci.com/g/xinningsu/html-query/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/html-query/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/xinningsu/html-query/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/html-query)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/xinningsu/html-query/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/g/xinningsu/html-query)\n[![Maintainability](https://api.codeclimate.com/v1/badges/18669386ce65532b228f/maintainability)](https://codeclimate.com/github/xinningsu/html-query/maintainability)\n\nA jQuery-like html processor written in PHP\n\n# Quick Start\n\n### Get contents\n```php\n\u003c?php\n\nuse Sulao\\HtmlQuery\\HQ;\n\n$html = '\n    \u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eHtml Query\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003ch1 class=\"title\"\u003ethis is title\u003c/h1\u003e\n        \u003cdiv class=\"content\"\u003ethis is \u003cb\u003econtent\u003c/b\u003e...\u003c/div\u003e\n    \u003c/body\u003e\n    \u003c/html\u003e\n';\n$hq = HQ::html($html);\n\necho $hq('.title')-\u003ehtml();\n//this is title\n\necho $hq('.content')-\u003ehtml();\n//this is \u003cb\u003econtent\u003c/b\u003e...\n\necho $hq('.content')-\u003eouterHtml();\n//\u003cdiv class=\"content\"\u003ethis is \u003cb\u003econtent\u003c/b\u003e...\u003c/div\u003e\n\necho $hq('.content')-\u003etext();\n//this is content...\n```\n\n### Set contents\n```php\n\u003c?php\n$html = '\n    \u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eHtml Query\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003ch1 class=\"title\"\u003ethis is title\u003c/h1\u003e\n        \u003cdiv class=\"content\"\u003ethis is \u003cb\u003econtent\u003c/b\u003e...\u003c/div\u003e\n    \u003c/body\u003e\n    \u003c/html\u003e\n';\n$hq = HQ::html($html);\n\necho $hq('.title')-\u003ehtml('this is new title')-\u003ehtml();\n//this is new title\n\necho $hq('.content')-\u003ehtml('this is \u003cb\u003enew content\u003c/b\u003e...')-\u003ehtml();\n//this is \u003cb\u003enew content\u003c/b\u003e...\n\necho $hq('.content')-\u003etext('this is new content...')-\u003ehtml();\n//this is new content...\n```\n\n### Get attributes\n```php\n\u003c?php\n\nuse Sulao\\HtmlQuery\\{HQ, HtmlQuery};\n\n$html = '\n    \u003cdiv class=\"container\"\u003e\n        \u003cimg src=\"1.png\"\u003e\n        \u003cimg src=\"2.png\"\u003e\n        \u003cdiv class=\"img\"\u003e\n            \u003cimg src=\"3.png\"\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n';\n$hq = HQ::html($html);\n\n$images = $hq('.container img')-\u003emap(function (DOMElement $node) {\n    return $node-\u003egetAttribute('src');\n});\nprint_r($images);\n//['1.png', '2.png', '3.png']\n\n// or resolve the DOMElement to HtmlQuery instance by type hinting\n$images = $hq('.container img')-\u003emap(function (HtmlQuery $node) {\n    return $node-\u003eattr('src');\n});\nprint_r($images);\n//['1.png', '2.png', '3.png']\n\n// Specified which node\necho $hq('.container img')-\u003eeq(1)-\u003eattr('src');\n//2.png\n\n// Or access the DOMNode like array\necho $hq('.container img')[1]-\u003egetAttribute('src');\n//2.png\n```\n\n### Change attributes\n```php\n\u003c?php\n\nuse Sulao\\HtmlQuery\\{HQ, HtmlQuery};\n\n$html = '\n    \u003cdiv class=\"container\"\u003e\n        \u003cimg src=\"1.png\" width=\"100\" onclick=\"zoom()\"\u003e\n        \u003cimg src=\"2.png\" width=\"100\" onclick=\"zoom()\"\u003e\n        \u003cdiv class=\"img\"\u003e\n            \u003cimg src=\"3.png\" width=\"200\" data-src=\"3\" onclick=\"zoom()\"\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n';\n$hq = HQ::html($html);\n$images = $hq('.container img');\n\n$images-\u003eremoveAttr('onclick');\necho $hq('.container')-\u003eouterHtml();\n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cimg src=\"1.png\" width=\"100\"\u003e\n    \u003cimg src=\"2.png\" width=\"100\"\u003e\n    \u003cdiv class=\"img\"\u003e\n        \u003cimg src=\"3.png\" width=\"200\" data-src=\"3\"\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n*/\n\n$images-\u003eremoveAllAttrs(['src']);\necho $hq('.container')-\u003eouterHtml();\n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cimg src=\"1.png\"\u003e\n    \u003cimg src=\"2.png\"\u003e\n    \u003cdiv class=\"img\"\u003e\n        \u003cimg src=\"3.png\"\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n*/\n\n$images-\u003eeach(function (DOMElement $node) {\n    $node-\u003esetAttribute('title', 'html query');\n});\n// Or resolve to HtmlQuery instance\n$images-\u003eeach(function (HtmlQuery $node, $index) {\n    $node-\u003eattr(['alt' =\u003e 'image ' . ($index + 1)]);\n});\necho $hq('.container')-\u003eouterHtml();\n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cimg src=\"1.png\" title=\"html query\" alt=\"image 1\"\u003e\n    \u003cimg src=\"2.png\" title=\"html query\" alt=\"image 2\"\u003e\n    \u003cdiv class=\"img\"\u003e\n        \u003cimg src=\"3.png\" title=\"html query\" alt=\"image 3\"\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n*/\n```\n\n### Change structure\n```php\n\u003c?php\n\nuse Sulao\\HtmlQuery\\HQ;\n\n$html = '\n    \u003cdiv class=\"container\"\u003e\n        \u003cimg src=\"1.png\"\u003e\n        \u003cimg src=\"2.png\"\u003e\n        \u003cdiv class=\"img\"\u003e\n            \u003cimg src=\"3.png\"\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n';\n$hq = HQ::html($html);\n\n$hq('.container img')-\u003enot('.img img')-\u003ewrap('\u003cdiv class=\"img\"\u003e\u003c/div\u003e');\necho $hq('.container')-\u003eouterHtml();\n// The indentation maybe not the same, but the html structure should be the same. \n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cdiv class=\"img\"\u003e\n        \u003cimg src=\"1.png\"\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"img\"\u003e\n        \u003cimg src=\"2.png\"\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"img\"\u003e\n        \u003cimg src=\"3.png\"\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n*/\n\n$hq('.container img')-\u003eunwrap();\necho $hq('.container')-\u003eouterHtml();\n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cimg src=\"1.png\"\u003e\n    \u003cimg src=\"2.png\"\u003e\n    \u003cimg src=\"3.png\"\u003e\n\u003c/div\u003e\n*/\n\n$hq('\u003cimg src=\"0.png\"/\u003e')-\u003eprependTo('.container');\n$hq-\u003efind('.container')-\u003eappend('\u003cimg src=\"4.png\"/\u003e');\necho $hq('.container')-\u003eouterHtml();\n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cimg src=\"0.png\"\u003e\n    \u003cimg src=\"1.png\"\u003e\n    \u003cimg src=\"2.png\"\u003e\n    \u003cimg src=\"3.png\"\u003e\n    \u003cimg src=\"4.png\"\u003e\n\u003c/div\u003e\n*/\n\n$hq(\"img[src='0.png']\")-\u003eremove();\n$hq(\"img[src='2.png']\")-\u003eafter('\u003cimg src=\"2.5.png\"/\u003e');\n$hq(\"img[src='1.png']\")-\u003ebefore($hq(\"img[src='4.png']\"));\necho $hq('.container')-\u003eouterHtml();\n/*\n\u003cdiv class=\"container\"\u003e\n    \u003cimg src=\"4.png\"\u003e\n    \u003cimg src=\"1.png\"\u003e\n    \u003cimg src=\"2.png\"\u003e\n    \u003cimg src=\"2.5.png\"\u003e\n    \u003cimg src=\"3.png\"\u003e\n\u003c/div\u003e\n*/\n```\n\n# Reference\n\n- [https://www.php.net/manual/en/book.dom.php](https://www.php.net/manual/en/book.dom.php)\n- [https://github.com/symfony/css-selector](https://github.com/symfony/css-selector)\n- [https://api.jquery.com/](https://api.jquery.com/)\n\n# License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxinningsu%2Fhtml-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxinningsu%2Fhtml-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxinningsu%2Fhtml-query/lists"}