function getPage($options = "", $page = "")
{
preg_match("/^https?/", $page, $scheme);
$scheme = $scheme[0] ?? null;
$scheme = !empty($scheme) ? $scheme : (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https" : "http");
$self = "{$_SERVER["REQUEST_SCHEME"]$scheme}://{$_SERVER["HTTP_HOST"]$_SERVER["SERVER_NAME"]}{$_SERVER["REQUEST_URI"]}";
/*
* - return the string untouched
* a - return the page name, extension, and get variables
* b - no extension, no get variable
* c - url up to extension, no get variable
* d - all get variables (everything after "?" excludes the "?") (if no "?" then sets to "")
* e - domain name e.g. google
* f - full domain without any page information e.g. httphttps://www.google.com
* g - fullurl domainup e.g.to http://www.google.com/search?q=querylast (overwritesfolder, allexcludes otherpage options)name
*/
if (empty($options)) return $self;
$options = str_split($options);
$page = ($page !== "") ? $page$self : $self;$page;
if (in_array("a", $options)) $page = substr($page, strrpos($page, "/") + 1);
if (in_array("b", $options)) $page = substr($page, 0, strrpos($page, ".php"));
if (in_array("c", $options)) $page = empty(substr($page, 0, strrpos($page, "?"))) ? $page : substr($page, 0, strrpos($page, "?"));
if (in_array("d", $options)) $page = (strpos($page, "?")) ? substr($page, strrpos($page, "?") + 1) : "";
if (in_array("e", $options)) $page = (strposexplode($page, "www'.")) ? substr($page', strposparse_url($page, "www.") + 4, strposgetPage($page, "."'f', strpos($page), "www.")PHP_URL_HOST) + 4)[1] :?? (parse_url(strposgetPage($page'f', "/localhost/"$page), PHP_URL_HOST) ?? substr($page,'localhost');
strpos($page, "://") + 3,if strpos($pagein_array("f", "localhost/"$options) + 2) :$page (strpos= ($page, "www"== $self) ? substr($page, strpos($page, "{$scheme}://") + 3, strlen($page) - strpos($page, "www.{$_SERVER["SERVER_NAME"]}") + 5) : substr($page, strpos($page, "{$scheme}://") + 3, .(strpos($page, "."$scheme) -=== strpos($page,false ? parse_url("{$scheme}://{$page}")["host"] -: 3)parse_url($page)["host"]);
if (in_array("f""g", $options)) if (preg_match("/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/", $page, $matches)) $page = $matches[0];
substr($page, if0, (in_arraystrrpos("g"$page, $options"/")) return $self;;
return $page;
}
Another example is to check if a link is external using getPage('e')
to return just the domain name.
A coded example being:
// Wrap in a div since XML must have one overall parent
$xml = simplexml_load_string('<div>'.$blog->story.'</div>');
// Iterate over all paragraph elements
foreach ($xml->children() as $p) {
// Get external links
// Here we specify the href of the anchor and see if the domain of the
// anchor is the same as the domain of the current page we are on, we
// will progress if the anchor points to an external site
if (isset($p->a['href']) && getPage('e', $p->a['href']) != getPage('e')) {
// Add the target attribute
$p->a->addAttribute('target', '_blank');
}
}
// Echo the HTML string
echo $xml->asXML();