{"id":26675539,"url":"https://github.com/sakibweb/phml","last_synced_at":"2025-03-26T03:18:38.494Z","repository":{"id":236118653,"uuid":"791952703","full_name":"sakibweb/PHML","owner":"sakibweb","description":"PHML is PHP to HTML Library","archived":false,"fork":false,"pushed_at":"2024-11-08T18:02:21.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-08T18:42:22.967Z","etag":null,"topics":["html","php","php-html","php-to-html","rendering","rendering-html","sakibweb"],"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/sakibweb.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-25T17:30:19.000Z","updated_at":"2024-11-08T18:02:25.000Z","dependencies_parsed_at":"2024-04-27T19:38:31.067Z","dependency_job_id":"fc1dc81d-305d-42a2-8958-4989ade47b04","html_url":"https://github.com/sakibweb/PHML","commit_stats":null,"previous_names":["sakibweb/phml"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakibweb","download_url":"https://codeload.github.com/sakibweb/PHML/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245579731,"owners_count":20638679,"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":["html","php","php-html","php-to-html","rendering","rendering-html","sakibweb"],"created_at":"2025-03-26T03:18:37.994Z","updated_at":"2025-03-26T03:18:38.482Z","avatar_url":"https://github.com/sakibweb.png","language":"PHP","readme":"# PHML\n## PHML is PHP to HTML Library\n\nPHML is a PHP library that simplifies the process of generating HTML markup dynamically. It provides a fluent and intuitive API for creating HTML elements, managing attributes, and handling nested structures.  It also offers powerful features to convert HTML to array/JSON formats and vice-versa, making it easy to work with HTML structures in your PHP applications.\n\n## Features\n\n* **Dynamic HTML Element Generation:** Create any HTML element using method calls matching the tag name.\n* **Attribute Management:** Easily add, modify, and remove attributes of HTML elements.\n* **Nested Structures:**  Create complex, nested HTML structures with ease.\n* **Array-Based Markup (ARML):** Define HTML structures using PHP arrays.\n* **JSON-Based Markup (JSML):** Generate HTML from JSON data.\n* **HTML to Array/JSON Conversion:** Convert HTML from a string, file, or URL into a PHP array or JSON.\n* **PHP Array to PHP Code:** Generate PHP code from a PHP array representing HTML structure.\n* **Automatic Tag Closure:** Correctly handles self-closing tags and ensures proper HTML structure.\n* **Resource Link Fixing:** Automatically fixes resource links (CSS, JS, images) when loading HTML from a URL.\n\n\n## Installation\n\nYou can simply include the `PHML.php` file in your project:\n\n```php\nrequire_once 'PHML.php';\n```\n\n## Usage\n\n### Dynamic Element Creation\n\n```php\necho PHML::div(['class' =\u003e 'container'], 'Hello, world!');\n\n// Output: \u003cdiv class=\"container\"\u003eHello, world!\u003c/div\u003e\n\necho PHML::img(['src' =\u003e 'image.jpg', 'alt' =\u003e 'An image']);\n\n// Output: \u003cimg src=\"image.jpg\" alt=\"An image\" /\u003e\n\necho PHML::a(['href' =\u003e 'https://example.com'], 'Click me');\n\n// Output: \u003ca href=\"https://example.com\"\u003eClick me\u003c/a\u003e\n\n\n// Create elements with unclosed tags.\necho PHML::p(['end' =\u003e false], 'This paragraph tag is not closed');\n\n// Output: \u003cp\u003eThis paragraph tag is not closed\n```\n\n### Nested Structures\n\n```php\necho PHML::div(\n    ['id' =\u003e 'main'],\n    PHML::h1('My Title'),\n    PHML::p(['class' =\u003e 'description'], 'Some text here.'),\n    PHML::ul(\n        PHML::li('Item 1'),\n        PHML::li('Item 2')\n    )\n);\n```\n\n### Array-Based Markup (ARML)\n\n```php\n\n$html_structure = [\n    'div' =\u003e [\n        'class' =\u003e 'container',\n        'inner' =\u003e [\n            'h1' =\u003e 'My Heading',\n            'p' =\u003e 'Some paragraph text.'\n        ]\n    ]\n];\n\necho PHML::arml($html_structure); \n```\n\n### JSON-Based Markup (JSML)\n\n```php\n$json = '{\n  \"div\": {\n    \"class\": \"content\",\n    \"inner\": {\n      \"h2\": \"Title\",\n      \"p\": \"Text content\"\n    }\n  }\n}';\n\necho PHML::jsml($json);\n```\n\n\n### HTML to Array/JSON\n\n```php\n// From a URL (with resource link fixing)\n$array = PHML::html('https://www.example.com', true);  // Returns an array\n$json = PHML::html('https://www.example.com', true, 'json'); // Returns a JSON string\n\n\n// From a string\n$htmlString = '\u003cdiv id=\"mydiv\"\u003e\u003ch1\u003eHello\u003c/h1\u003e\u003cp\u003eWorld!\u003c/p\u003e\u003c/div\u003e';\n$array = PHML::html($htmlString);\n\n\n// From a file\n$array = PHML::html('path/to/file.html');\nprint_r($array);\n\n// Specific function to load from a link and optionally get JSON output:\n$array = PHML::htmlFromLink('https://www.example.com');\n$json = PHML::htmlFromLink('https://www.example.com', true); // Get JSON output\n\n```\n\n\n### PHP Array to PHP Code\n\n```php\n$html_array = [\n    'div' =\u003e [\n        'class' =\u003e 'container',\n        'inner' =\u003e 'Hello'\n    ]\n];\n\necho PHML::php($html_array);\n\n// Output: \n// array(\n//     'div' =\u003e array(\n//         'class' =\u003e 'container',\n//         'inner' =\u003e 'Hello',\n//     ),\n// );\n// ?\u003e\n\n```\n\n\n## Contributing\n\nContributions are welcome!  Please feel free to submit pull requests or open issues.\n\n## License\n\nThis project is licensed under the MIT License.  See the LICENSE file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakibweb%2Fphml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakibweb%2Fphml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakibweb%2Fphml/lists"}