drpph80800 2016-11-28 11:40
浏览 26
已采纳

php循环通过域列表文件并删除子域

I want to list a "file" with sub.domain.tld names, remove sub and list uniqe domain.tld names

I can't figure out why my output ($list) doubles the last line "voorbeeld.nl"

<?php
$lines=file("list.txt");

$list = array();  //create empty array
foreach ($lines as $line_num => $line) {
        $line_explode = explode('.', $line);
        array_push($list, $line_explode[1] .'.'. $line_explode[2]);

}
echo "<br>-----------<br>"; 
foreach(array_unique($list) as $Resuld){ 
    echo '>' . $Resuld .'< <br>'; 
}
echo "-----------<br>"; ? >

list.txt:

sub1.example.nl
sub2.example.nl
sub1.example.com
sub2.example.com
sub3.example.com
sub1.voorbeeld.nl
sub2.voorbeeld.nl
sub3.voorbeeld.nl

result:

-----------
>example.nl < 
>example.com < 
>voorbeeld.nl < 
>voorbeeld.nl< 
-----------
  • 写回答

2条回答 默认 最新

  • duanbairan4235 2016-11-28 11:46
    关注

    Check link https://eval.in/686821 This is working fine

    In your output, I can see an extra space. Most probably, that can be reson for your issue.

    >voorbeeld.nl < 
    >voorbeeld.nl< 
    

    Modify your code as follows

    array_push($list, trim($line_explode[1]) .'.'. trim($line_explode[2]));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?