mirror of
https://github.com/YGGverse/gemini-php.git
synced 2025-09-10 05:02:39 +00:00
add Body::findLinks method
This commit is contained in:
parent
e3f4786f9e
commit
008d191d3c
10
README.md
10
README.md
@ -86,6 +86,16 @@ var_dump(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Body::findLinks
|
||||||
|
|
||||||
|
Find context links by protocol as argument, `gemini` by default
|
||||||
|
|
||||||
|
```
|
||||||
|
var_dump(
|
||||||
|
$body->findLinks('http') // returns array of http links found
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### Link
|
### Link
|
||||||
|
|
||||||
Inline links parser.
|
Inline links parser.
|
||||||
|
@ -83,4 +83,26 @@ class Body
|
|||||||
|
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findLinks(string $protocol = 'gemini'): array
|
||||||
|
{
|
||||||
|
$matches = [];
|
||||||
|
|
||||||
|
foreach ($this->_lines as $line)
|
||||||
|
{
|
||||||
|
if (preg_match('/' . $protocol . ':\/\/(.*)[\s\S\'"]*/', trim($line), $match))
|
||||||
|
{
|
||||||
|
$matches[] =
|
||||||
|
sprintf(
|
||||||
|
'%s://%s',
|
||||||
|
$protocol,
|
||||||
|
trim(
|
||||||
|
$match[1]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $matches;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user