How do I delete text out of a string?

I’m writing a function that will return the host of a domain name using php’s parse_url function. It takes in an array of domain names and returns the TLD for each one. I’ve already gotten it to add “http://” to each domain, but some of the domains in the array end in a period (as they can) - the problem is, parse_url doesn’t recognize the url if this period is there. How can I delete the period? Here’s my code for the function so far…


$domains = array('', '', '', '', '');

print_r ($domains);

echo "<br />";

foreach ($domains as &$name) {

$name = "http://" . $name;

$parsed_url = parse_url($name);

$hostname = explode('.' , $parsed_url[host]);

$count = count($hostname) - 1;
$name = $hostname[$count];


print_r ($domains);


$name = rtrim("http://" . $name, '.');