{"id":21453387,"url":"https://github.com/amal/cdom","last_synced_at":"2025-07-14T23:31:38.362Z","repository":{"id":142583271,"uuid":"2555732","full_name":"amal/CDom","owner":"amal","description":"Simple HTML/XML/BBCode DOM component for PHP.","archived":false,"fork":false,"pushed_at":"2011-11-01T15:44:45.000Z","size":234,"stargazers_count":26,"open_issues_count":0,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-18T03:16:09.304Z","etag":null,"topics":["anizoptera-cmf","bbcode","css-selector","css3-selectors","dom","dom-components","html","markup-language","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-10-11T14:17:24.000Z","updated_at":"2023-12-23T10:53:16.000Z","dependencies_parsed_at":"2023-03-14T07:15:47.118Z","dependency_job_id":null,"html_url":"https://github.com/amal/CDom","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amal%2FCDom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amal%2FCDom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amal%2FCDom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amal%2FCDom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amal","download_url":"https://codeload.github.com/amal/CDom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226002936,"owners_count":17558153,"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":["anizoptera-cmf","bbcode","css-selector","css3-selectors","dom","dom-components","html","markup-language","php","php-library"],"created_at":"2024-11-23T04:39:27.916Z","updated_at":"2024-11-23T04:39:28.483Z","avatar_url":"https://github.com/amal.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"CDom\n====\n\nhttps://github.com/amal/CDom\n\nCDom is a simple HTML/XML/BBCode DOM component.\nIt provides a parser for HTML-like markup language in the DOM-like structure and support searching through the DOM with full strength of CSS3 selectors and any manipulations.\nCDom is based on [PHP Simple HTML DOM Parser](http://simplehtmldom.sourceforge.net/) and licensed under the MIT License.\n\nMain features and possibilites:\n\n* Traversing and manipulations in jQuery-like manner for PHP.\n* Automatic detection of encoding.\n* Supports damaged and malformed html.\n* Full support of [CSS3 selectors](http://www.w3.org/TR/css3-selectors/).\n* Support of [jQuery selector extensions](http://api.jquery.com/category/selectors/jquery-selector-extensions/).\n* Extract contents from DOM as text or html in a single line.\n* Full code coverage.\n* Can work with simple BBCode or other HTML-like markup languages.\n\nCDom is written for Anizoptera CMF by Amal Samally (amal.samally at gmail.com)\n\n\nDocumentation\n-------------\n\nCDom use is very simple. Most of the methods match the jQuery's ones. All methods are detail commented. Your IDE can easy show autocompletion, if support PHPDoc. And you can see examples of using below.\nFull documentation will be soon.\n\n\nRequirements\n------------\n\n* CDom requires PHP 5.3.0 (or later).\n\n\nExamples\n--------\n\nHow to get HTML elements?\n\n```php\n// Create DOM from string\n$html = file_get_contents('http://www.google.com/');\n$dom  = CDom::fromString($html);\n\n// Find all images\nforeach($dom-\u003efind('img') as $element) {\n\techo $element-\u003esrc . \"\\n\";\n}\n\n// Find all links\nforeach($dom-\u003efind('a') as $element) {\n\techo $element-\u003ehref . \"\\n\";\n}\n```\n\n\nHow to modify HTML elements?\n\n```php\n// Create DOM from string\n$dom = CDom::fromString('\u003cdiv id=\"hello\"\u003eHello\u003c/div\u003e\u003cdiv id=\"world\"\u003eWorld\u003c/div\u003e');\n\n// Add class to the second div (first last child)\n$dom-\u003efind('div:nth-last-child(1)')-\u003eclass = 'bar';\n\n// Change text of first div\n$dom-\u003efind('div[id=hello]')-\u003etext('foo');\n\necho $dom . \"\\n\"; // Output: \u003cdiv id=\"hello\"\u003efoo\u003c/div\u003e\u003cdiv id=\"world\" class=\"bar\"\u003eWorld\u003c/div\u003e\n```\n\n\nExtract contents from HTML\n\n```php\n$html = file_get_contents('http://www.google.com/');\n// Dump correctly formatted contents without tags from HTML\necho CDom::fromString($html)-\u003etext() . \"\\n\";\n```\n\n\nUse CDom to work with simple BBCode\n\n```php\n$bbMarkup = \u003c\u003c\u003c'TXT'\n[quote]\n\t[b]Bold [u]Underline[/u][/b]\n\t[i]Italic\n[/quote]\n[img width=12 height=16]url[/img]\nTXT;\nCDom::$bracketOpen  = '[';\nCDom::$bracketClose = ']';\n\nCDom::$blockTags  = array('quote' =\u003e true);\nCDom::$inlineTags = array('b' =\u003e true, 'i' =\u003e true, 'u' =\u003e true);\nCDom::$selfClosingTags = array();\n\n// Create DOM from string\n$dom = CDom::fromString($bbMarkup);\n\n// Find [b]\n$b = $dom-\u003efind('b');\n$expected = '[b]Bold [u]Underline[/u][/b]';\necho $b-\u003eouterHtml() . \"\\n\"; // Output: [b]Bold [u]Underline[/u][/b]\n\n// Change [img] width\n$img = $dom-\u003elastChild;\n$img-\u003ewidth = 450;\necho $img-\u003eouterHtml() . \"\\n\"; // Output: [img width=\"450\" height=\"16\"]url[/img]\n\n// Convert [b] to html\nCDom::$bracketOpen  = '\u003c';\nCDom::$bracketClose = '\u003e';\necho $b-\u003eouterHtml() . \"\\n\"; // Output: \u003cb\u003eBold \u003cu\u003eUnderline\u003c/u\u003e\u003c/b\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famal%2Fcdom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famal%2Fcdom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famal%2Fcdom/lists"}