https://github.com/talesoft/tale-dom
https://github.com/talesoft/tale-dom
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/talesoft/tale-dom
- Owner: Talesoft
- License: mit
- Created: 2016-02-21T13:35:12.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-20T22:10:16.000Z (about 10 years ago)
- Last Synced: 2025-07-17T05:05:28.624Z (about 1 year ago)
- Language: PHP
- Size: 33.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Tale Dom
**A Tale Framework Component**
# What is Tale Dom?
# Installation
Install via Composer
```bash
composer require "talesoft/tale-dom:*"
composer install
```
# Usage
## Parsing
```php
use Tale\Dom;
$element = Dom::fromString('
Hello World!
');
var_dump($element->getName()); //h1
var_dump($element->getText()); //Hello World!
```
# Manipulation
```php
use Tale\Dom;
$m = Dom::manipulate('');
$m->append('db')
->append('host')->setText('localhost')
->after('password')->setText('12345')
->parent
->after('logging')
->append('adapter')->setText('file')
->append('path')->setText('./errors.log')
echo $m; //localhost12345...
```
...or shorter...
```php
use Tale\Dom;
$m = Dom::manipulate('
');
$m->query('host')->setText('localhost');
$m->query('db > password')->setText('12345');
$m->query('logging adapter')->setText('file');
$m->query('#logPath')->setText('./errors.log');
echo $m; //localhost12345...
```
...or even shorter...
```php
use Tale\Dom;
$m = Dom::manipulate([
'config' => [
'host' => 'localhost',
'password' => '12345'
],
'logging' => [
'adapter' => 'file',
'path#logPath'
]
]);
$m->query('#logPath')->setText('./errors.log');
echo $m; //localhost12345...
```
## Dumping
```php
use Tale\Dom;
$element = Dom::fromString([
'html' => [
'head' => [
'meta[charset="utf-8"]',
'title' => 'My awesome Tale Dom Website!'
]
]
]);
$prettyFormatter = new Dom\Formatter(['pretty' => true]);
$htmlFormatter = new Dom\Html\Formatter(['pretty' => true]);
echo $element; //...
echo $element->getString($prettyFormatter);
/*
My awesome Tale Dom Website!
...
*/
echo $element->getString($htmlFormatter);
/*
My awesome Tale Dom Website!
...
*/
```