mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-04-01 09:25:29 +00:00
implement getLinks method
This commit is contained in:
parent
35893d2db2
commit
590096afef
2 changed files with 45 additions and 4 deletions
|
|
@ -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(
|
||||
'/^[\s]?#([^#]+)/',
|
||||
$regex,
|
||||
$line,
|
||||
$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