使用php从文本文件中提取非重复的电话号码

I have done this code by the help of google and this website stackoverflow, thank you very much to all of you pros out there I salute all of you :)

But I have a little problem which is it prints out duplicate numbers

I have this code bellow

$link = file_get_contents("file.txt");
    if(preg_match_all('/\b[0-9]{3}\s*[-]?\s*[0-9]{3}\s*[-]?\s*[0-9]{4}\b/', $link, $content, PREG_PATTERN_ORDER)){
        $i = 0;
        if(!empty($content[0][$i])){ 
            while(!empty($content[0][$i])){
                echo "<br/>";
                echo $content[0][$i];
                $i++;
            }
        }
    }

file.txt

Name: 
Phone: 1477276084
Name: 
Phone: 2958692011
Name: 
Phone: 2958692011
Name: 
Phone: 2958692011
Name: 
Phone: 9954129334
Name: 
Phone: 123-812-4181
Name: 
Phone: 609-182-5123
Name: 
Phone: 609-182-5123
Name: 
Phone: 609-182-5123
Name: 
Phone: 609-182-5123
$link = file_get_contents("file.txt");
if(preg_match_all('/\b[0-9]{3}\s*[-]?\s*[0-9]{3}\s*[-]?\s*[0-9]{4}\b/', $link, $content, PREG_PATTERN_ORDER)){

    $content = array_unique($content[0]);
    foreach($content as $key=>$value)
    {
        echo $value;
        echo "<br>";
    }

}

Simple solution:

I understand you are a newbie. You probably need a simple solution You can keep an array of detected phone numbers and if the new number is not available in the array, print it.

$link = file_get_contents("file.txt");
$detected = array();
if(preg_match_all('/\b[0-9]{3}\s*[-]?\s*[0-9]{3}\s*[-]?\s*[0-9]{4}\b/', $link, $content, PREG_PATTERN_ORDER)){
    $i = 0;
    if(!empty($content[0][$i])){ 
        while(!empty($content[0][$i])){
            if (!in_array($content[0][$i], $detected))
            {
                $detected[] =  $content[0][$i];
                echo "<br/>";
                echo $content[0][$i];
                $i++;
            }
        }
    }
}

Check this way, first create a unique array, then loop it.

$link = file_get_contents("file.txt");
$phoneArray = array();
preg_match_all('/\b[0-9]{3}\s*[-]?\s*[0-9]{3}\s*[-]?\s*[0-9]{4}\b/', $link, $content, PREG_PATTERN_ORDER);

$phoneArray = array_unique($content[0]);

foreach($phoneArray as $number){
    echo $number;
    echo "<br/>";
}