Tedd's REGEX Solution

Single Matches: 5

Array
(
    [0] => 656-45-7752
    [1] => 555-43-5743
    [2] => 666-44-7770
    [3] => 567-66-4321
    [4] => 567-44-4321
)

String Searched

Name: Sam Parker
Phone: 517-333-1345
SS: 656-45-7752
Dr Lic: 345-678-123-456
Zip Code: 48910-3465


Name: Mary Parker
Phone: 517.333.1334
SS: 555-43-5743
Dr Lic: 333.478.646.233
Zip Code: 48910.3464


Name: Joe Spade
Phone: 517/289/0453
SS: 666-44-7770
Dr Lic: 123/456/789/001
Zip Code: 48910


Name: Matt Buds
Phone: 517 393 1556
SS: 567-66-4321
Dr Lic: 123 654 987 002
Zip Code: 48910 3457


Name: Karen Klutz
Phone: 517-393.1446
SS: 567-44-4321
Dr Lic: 123/654-987.002
Zip Code: 48910 3457
 

CODE FOLLOWS

<?php
    
include('includes/header.php');
?>

    <h1>Tedd's REGEX Solution</h1>

<?php

    
// the following is the string to search

    
$str = <<<EOD
Name: Sam Parker
Phone: 517-333-1345
SS: 656-45-7752
Dr Lic: 345-678-123-456
Zip Code: 48910-3465
<br>
Name: Mary Parker
Phone: 517.333.1334
SS: 555-43-5743
Dr Lic: 333.478.646.233
Zip Code: 48910.3464
<br>
Name: Joe Spade
Phone: 517/289/0453
SS: 666-44-7770
Dr Lic: 123/456/789/001
Zip Code: 48910
<br>
Name: Matt Buds
Phone: 517 393 1556
SS: 567-66-4321
Dr Lic: 123 654 987 002
Zip Code: 48910 3457
<br>
Name: Karen Klutz
Phone: 517-393.1446
SS: 567-44-4321
Dr Lic: 123/654-987.002
Zip Code: 48910 3457
EOD;

    
// this pattern works for SS numbers seperated by "-"
    // 3 numbers seperated by - then 2 numbers seperated by - and then 4 numbers
    
$pattern '/\b[0-9]{3}(-)[0-9]{2}(-)[0-9]{4}\b/';

    
// ==== single preg_match_all() search
    
$results = array();

    
// do preg_match_all
    
$count preg_match_all($pattern$str$results);

    echo(
"<p>Single Matches: $count</p>");
    echo(
'<pre>');
    
print_r($results[0]);
    echo(
'</pre>');

    echo(
'<h2>String Searched</h2>');
    echo(
nl2br($str));

    include(
'includes/footer.php');
?>