Remove domain extension

前端 未结 5 1158
情书的邮戳
情书的邮戳 2020-11-30 14:10

So let\'s say I have just-a.domain.com,just-a-domain.info,just.a-domain.net how can I remove the extension .com,.net.info ... and I need the result

5条回答
  •  一向
    一向 (楼主)
    2020-11-30 14:53

    $subject = 'just-a.domain.com';
    $result = preg_split('/(?=\.[^.]+$)/', $subject);
    

    This produces the following array

    $result[0] == 'just-a.domain';
    $result[1] == '.com';
    

提交回复
热议问题