{"id":27251494,"url":"https://github.com/scarletsfiction/scarletsquery","last_synced_at":"2025-04-11T01:10:09.310Z","repository":{"id":62540960,"uuid":"144708077","full_name":"ScarletsFiction/ScarletsQuery","owner":"ScarletsFiction","description":"A high performance HTML or XML query selector/parser for PHP that almost like jQuery","archived":false,"fork":false,"pushed_at":"2019-04-07T02:52:52.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T01:10:01.362Z","etag":null,"topics":["dom-parser","jquery","parse","php","selector-query","xml"],"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/ScarletsFiction.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":"2018-08-14T10:58:32.000Z","updated_at":"2020-10-26T13:49:25.000Z","dependencies_parsed_at":"2022-11-02T15:45:22.113Z","dependency_job_id":null,"html_url":"https://github.com/ScarletsFiction/ScarletsQuery","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FScarletsQuery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FScarletsQuery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FScarletsQuery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FScarletsQuery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScarletsFiction","download_url":"https://codeload.github.com/ScarletsFiction/ScarletsQuery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322601,"owners_count":21084337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dom-parser","jquery","parse","php","selector-query","xml"],"created_at":"2025-04-11T01:10:08.476Z","updated_at":"2025-04-11T01:10:09.305Z","avatar_url":"https://github.com/ScarletsFiction.png","language":"PHP","funding_links":["https://www.patreon.com/stefansarya"],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://www.patreon.com/stefansarya\"\u003e\u003cimg src=\"http://anisics.stream/assets/img/support-badge.png\" height=\"20\"\u003e\u003c/a\u003e\n\n[![Written by](https://img.shields.io/badge/Written%20by-ScarletsFiction-%231e87ff.svg)](https://github.com/ScarletsFiction/)\n[![Software License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](LICENSE)\n[![Build Status](https://api.travis-ci.org/ScarletsFiction/ScarletsQuery.svg?branch=master)](https://travis-ci.org/ScarletsFiction/ScarletsQuery)\n[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=ScarletsQuery%20is%20a%20high%20performance%20HTML%20or%20XML%20query%20selector/parser%20for%20PHP%20that%20almost%20like%20jQuery\u0026url=https://github.com/ScarletsFiction/ScarletsQuery\u0026via=github\u0026hashtags=scarlets,dom,parser,query,php)\n\n# ScarletsQuery\nScarletsQuery is a high performance HTML or XML query selector/parser for PHP that almost like jQuery.\n\n## Installation instruction\n\nClone/download this repository and include `ScarletsQuery.php`\n\n### Install with composer\n\u003e composer require scarletsfiction/scarletsquery\n\n## Available Methods\nThis library query selector is designed like jQuery's queryselector.\u003cbr\u003e\nBut there are different method to obtain the data.\n\n### MarkupLanguage\nThis class will handle every selector query and parse Markup Language.\n\n\u003e MarkupLanguage::parseText($string);\n\nParse HTML/XML to structured array as `MarkupLanguageElementCollection`\n\n### MarkupLanguageElementCollection\nThis class have a collection of Element Tree, you can also obtain the value just like an array `$collection[0]` and it will return `MarkupLanguageElement`.\n\n\u003e $dom-\u003elength;\n\nReturn length of Element Collection\n\n\u003e $dom-\u003eview;\n\nReturn raw array of the Element Collection\n\n\u003e $dom-\u003eselector($query);\n\nReturn the result as `MarkupLanguageElementCollection`\n\n\u003e $dom-\u003eparent();\n\nReturn parent of all result as `MarkupLanguageElementCollection`\n\n\u003e $dom-\u003econtent($index = false);\n\nReturn content of all result as `Array`\nIf `$index` specified, it will return the content as `String`\n\n### MarkupLanguageElement\nThis class have a collection of Element Tree, you can also obtain the value just like an array `$collection[0]` and it will return `MarkupLanguageElement`.\n\n\u003e $dom-\u003eview;\n\nReturn raw array of the Element\n\n\u003e $dom-\u003eselector($query);\n\nReturn the result as `MarkupLanguageElement`\n\n\u003e $dom-\u003eparent();\n\nReturn the element's parent `MarkupLanguageElement`\n\n\u003e $dom-\u003ehasClass($class);\n\nReturn `true` if found and vice-versa\n\n\u003e $dom-\u003enext($jump = 1);\n\nReturn the next sibling element as `MarkupLanguageElement`\n\n\u003e $dom-\u003econtent();\n\nReturn the content as `String`\n\n\u003e $dom-\u003eattr($property);\n\nReturn element property as `String` or `null` if not found\n\n## Example Usage\n\n```html\n\u003cul\u003e\n  \u003cli class='account'\u003e\n    \u003cspan active id=\"name\"\u003eAlex\u003c/span\u003e\n    \u003cspan active id=\"1\"\u003e1a\u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli class=\"account\"\u003e\n    \u003cspan active id='nickname'\u003eSteven\u003c/span\u003e\n    \u003cspan active id=\"2\"\u003e2b\u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli class=\"profile\"\u003e\n    \u003cspan active id=\"name\"\u003eElisabeth\u003c/span\u003e\n    \u003cspan active id=\"3\"\u003e3c\u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli class=\"account\"\u003e\n    \u003cspan active id=\"name\"\u003eLuffy\u003c/span\u003e\n    \u003cspan active id=\"4\"\u003e4d\u003c/span\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n```\n\nAnd below is the PHP script\n\n```php\n$html = file_get_contents('sample.html');\n$dom = Scarlets\\Library\\MarkupLanguage::parseText($html);\n\n// Select element that have 'name' id and get these content\n$dom-\u003eselector('#name')-\u003econtent();\n/* Output\n    Array\n    (\n        [0] =\u003e Alex\n        [1] =\u003e Elisabeth\n        [2] =\u003e Luffy\n    )\n*/\n\n/*\n  1. Select element that have 'ul' tag\n  2. Select the child with '3' id\n  3. Select the element before it { next(-1) }\n  4. Get the content\n*/\n$dom-\u003eselector('ul #3')[0]-\u003enext(-1)-\u003econtent();\n/* Output\n    Elisabeth\n*/\n\n// Select 'ul' tag and the child with 'li' tag\n$contents = $dom-\u003eselector('ul li');\n\n// Iterate over the result\nfor ($i=0; $i \u003c $contents-\u003elength; $i++) {\n\n    // Check if the element has 'profile' class\n    if($contents[$i]-\u003ehasClass('profile')){\n\n        // Select the child with 'span' tag\n        // And get the second content\n        print_r($contents[$i]-\u003eselector('span')-\u003econtent(1));\n    }\n}\n/* Output\n    3c\n*/\n```\n\n## Contribution\n\nIf you want to help in ScarletsQuery, please fork this project and edit on your repository, then make a pull request to here.\n\nKeep the code simple and clear.\n\n## License\n\nScarletsQuery is under the MIT license.\n\nHelp improve this framework by support the author ＼(≧▽≦)／","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarletsfiction%2Fscarletsquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscarletsfiction%2Fscarletsquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarletsfiction%2Fscarletsquery/lists"}