mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-03-31 17:05:29 +00:00
implement getLinks method
This commit is contained in:
parent
35893d2db2
commit
590096afef
2 changed files with 45 additions and 4 deletions
20
README.md
20
README.md
|
|
@ -75,15 +75,33 @@ echo $reader->toGemini(
|
||||||
Get document title
|
Get document title
|
||||||
|
|
||||||
```
|
```
|
||||||
echo $reader->getH1(
|
$gemini = $reader->toGemini(
|
||||||
file_get_contents(
|
file_get_contents(
|
||||||
'/host/data/pages/index.txt'
|
'/host/data/pages/index.txt'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
echo $reader->getH1(
|
||||||
|
$gemini
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Reader::getLinks
|
#### Reader::getLinks
|
||||||
|
|
||||||
|
Get document links
|
||||||
|
|
||||||
|
```
|
||||||
|
$gemini = $reader->toGemini(
|
||||||
|
file_get_contents(
|
||||||
|
'/host/data/pages/index.txt'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
echo $reader->getLinks(
|
||||||
|
$gemini
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### Filesystem
|
### Filesystem
|
||||||
|
|
||||||
Provides methods for simple and secure interaction with DokuWiki file storage
|
Provides methods for simple and secure interaction with DokuWiki file storage
|
||||||
|
|
|
||||||
|
|
@ -246,12 +246,12 @@ class Reader
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getH1(string $data): ?string
|
public function getH1(string $gemini, ?string $regex = '/^[\s]?#([^#]+)/'): ?string
|
||||||
{
|
{
|
||||||
foreach ((array) explode(PHP_EOL, $data) as $line)
|
foreach ((array) explode(PHP_EOL, $gemini) as $line)
|
||||||
{
|
{
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/^[\s]?#([^#]+)/',
|
$regex,
|
||||||
$line,
|
$line,
|
||||||
$matches
|
$matches
|
||||||
);
|
);
|
||||||
|
|
@ -266,4 +266,27 @@ class Reader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLinks(string $gemini, ?string $regex = '/[A-z]+:\/\/\S+/'): array
|
||||||
|
{
|
||||||
|
$links = [];
|
||||||
|
|
||||||
|
preg_match_all(
|
||||||
|
$regex,
|
||||||
|
$gemini,
|
||||||
|
$matches
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($matches[0]))
|
||||||
|
{
|
||||||
|
foreach ((array) $matches[0] as $link)
|
||||||
|
{
|
||||||
|
$links[] = trim(
|
||||||
|
$link
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue