如何在没有www的情况下显示网址名称?
如果网址为
如何制作这样的?
google.com
我的代码
interface ICommand
{
public function execute(Game $game) : void;
}
class RollDiceCommand implements ICommand
{
private $player;
public function __construct(Player $player)
{
$this->player = $player;
}
public function execute(Game $game) : void
{
$dice = DiceFacade::roll(new NumberGenerator());
// Currently a business logic goes here
if ($dice->isDouble()) {
$player->incrementDoubleCount();
if ($player->getDoubleCount() === 3) {
$command = new GoToJailCommand();
$command->execute();
return;
}
} else {
// The next player turn
$game->nextPlayer();
}
$command = MoveForwardCommand($this->player);
$command->execute($dice->getValue());
// ...
}
}
答案 0 :(得分:1)
$url = 'http://sub.example.com/path?googleguy=googley';
$test = parse_url($url);
$string = explode('.',$test["host"]);
$top_lev_dom = array("com","net","us","gov","io","xyz","org","int","edu");
$output;
$end = false;
$pos = 0;
$pos2;
for($i = 0; $i < count($string); $i++){
for($x = 0; $x < count(top_lev_dom); $x++){
if($string[$i]==$top_lev_dom[$x]){
$pos = $i;
$pos2 = $i - 1;
$end = true;
break;
}
if($end == true){break;}
}
if($end == true){break;}
}
if($pos==0){
$output = "error";
}else{
$output.=$string[$pos2].".".$string[$pos];
}
echo $output;
example.com