mirror of
https://github.com/YGGverse/gemtext-php.git
synced 2026-03-31 17:55:38 +00:00
add examples
This commit is contained in:
parent
2643878aae
commit
588a8750fb
1 changed files with 63 additions and 0 deletions
63
README.md
Normal file → Executable file
63
README.md
Normal file → Executable file
|
|
@ -8,4 +8,67 @@ This library is lightweight, object-oriented [Gemtext](https://geminiprotocol.ne
|
|||
|
||||
``` bash
|
||||
composer require yggverse/gemtext:dev-main
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Parse existing document
|
||||
|
||||
``` php
|
||||
// Load document from file
|
||||
$document = new \Yggverse\Gemtext\Document(
|
||||
file_get_contents(
|
||||
'tests/data/document.gmi'
|
||||
)
|
||||
);
|
||||
|
||||
// Get links
|
||||
foreach ($document->getLinks() as $link)
|
||||
{
|
||||
print(
|
||||
$link->toString()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### Make new document
|
||||
|
||||
``` php
|
||||
// Init new document
|
||||
$document = new \Yggverse\Gemtext\Document;
|
||||
|
||||
// Append header
|
||||
$document->append(
|
||||
new \Yggverse\Gemtext\Entity\Header(
|
||||
'Hello world'
|
||||
)
|
||||
);
|
||||
|
||||
// Init new link
|
||||
$link = new \Yggverse\Gemtext\Entity\Link(
|
||||
'gemini://geminiprotocol.net',
|
||||
'The Gemini Program',
|
||||
'1965-01-19'
|
||||
);
|
||||
|
||||
// Change link date
|
||||
$link->setDate(
|
||||
date('Y-m-d')
|
||||
);
|
||||
|
||||
// Append link to document
|
||||
$document->append(
|
||||
$link
|
||||
);
|
||||
|
||||
// Get gemtext result
|
||||
print(
|
||||
$document->toString()
|
||||
);
|
||||
|
||||
// Save to file
|
||||
file_put_contents(
|
||||
'/path/to/file.gmi',
|
||||
$document->toString()
|
||||
)
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue