<?
/*
* This function checks for http:// and adds it if necessary
*/
$input = "google.de/#q=hallo";
function addhttp($input) {
if (!preg_match("~^(?:f|ht)tps?://~i", $input)) {
$input = "http://" . $input;
}
return $input;
}
$output = addhttp($input);
//-> http://google.de/#q=hallo
/*
* Get the HOST from Domain
*/
$domain = str_ireplace('www.', '', parse_url($output, PHP_URL_HOST));
//-> google.de
/*
* Example
*/
echo '<a href="'.$output.'">'.$domain.'</a>';
?>
<a href="http://google.de/#q=hallo">google.de</a>
/* google.de/#q=hallo -> http://google.de/#q=hallo -> google.de */
Check for http:// in URL and get HOST for clean Anchor Links
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.