PHP Capturing With Preg_Match() – String Function

if (preg_match('/^(\d{5})(-\d{4})?$/',$_POST['zip'],$matches)) {
    print "$matches[0] is a valid US ZIP Code\n";
    print "$matches[1] is the five-digit part of the ZIP Code\n";
    if (isset($matches[2])) {
        print "The ZIP+4 is $matches[2];";
    } else {
        print "There is no ZIP+4";
}$is_bold = preg_match('@<b>([^<]+)</b>@',$html,$matches);
if ($is_bold) {
    print "The bold text is: $matches[1]";

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.