Here is some code that might help. parse_url() will get you the host name, so your first question is easy to fix.
Your second is a little harder. This code breaks down a string into an array and then removes elements until the length of the array is less than the size. It then adds a ellipsis to the array.
ellipsis = ...is a mark or series of marks that usually indicate an intentional omission...
See how you go
<?php
function ReduceString($string, $seperator, $size)
{
$array = explode($seperator, $string);
if (strlen(implode($seperator, $array)) > $size)
{
do {
array_shift($array);
} while (strlen(implode($seperator,$array)) > $size);
array_unshift($array, "[...]");
}
return implode($seperator,$array);
}
$href = "http://maps.google.com/maps/test/hello/there/from/derek?f=q&source=s_q&hl=en&geocode=&q=21";
$url = parse_url($href);
$path = ReduceString($url["path"], "/", 15);
$query = ReduceString($url["query"], "&", 15);
echo "<a href=$href>".$url["host"].$path."?$query</a>";
?>