Marverick M. Marverick M. - 1 month ago 7
PHP Question

extract non duplicated phone numbers from text file using 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

Answer
$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>";
    }

}