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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献