mirror of
https://github.com/YGGverse/yo-tools-php.git
synced 2026-03-31 17:55:32 +00:00
Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cce1b03e4 |
1 changed files with 0 additions and 43 deletions
43
src/Link.php
43
src/Link.php
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Yggverse\YoTools;
|
|
||||||
|
|
||||||
class Link
|
|
||||||
{
|
|
||||||
public static function relative2absolute(
|
|
||||||
string $source, // current document url to grab the base
|
|
||||||
string $target, // relative or absolute link
|
|
||||||
?string &$scheme = null,
|
|
||||||
?string &$host = null,
|
|
||||||
?int &$port = null
|
|
||||||
): string
|
|
||||||
{
|
|
||||||
if (!parse_url($target, PHP_URL_HOST))
|
|
||||||
{
|
|
||||||
$scheme = parse_url($source, PHP_URL_SCHEME);
|
|
||||||
$host = parse_url($source, PHP_URL_HOST);
|
|
||||||
$port = parse_url($source, PHP_URL_PORT);
|
|
||||||
|
|
||||||
return $scheme . '://' . $host . ($port ? ':' . $port : null) .
|
|
||||||
'/' .
|
|
||||||
trim(
|
|
||||||
ltrim(
|
|
||||||
str_replace(
|
|
||||||
[
|
|
||||||
'./',
|
|
||||||
'../'
|
|
||||||
],
|
|
||||||
'',
|
|
||||||
$target
|
|
||||||
),
|
|
||||||
'/'
|
|
||||||
),
|
|
||||||
'.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue