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条)

报告相同问题?

悬赏问题

  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要