PHP code example of storagemadeeasy / contentdetectors

1. Go to this page and download the library: Download storagemadeeasy/contentdetectors library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

storagemadeeasy / contentdetectors example snippets




// Require composer autoload
rs\DetectionManager();

$matches = $manager->getMatchingTypes($content);
foreach ($matches as $match) {
    // Get the match type, e.g. Passport Number
    $type = $match->getMatchType();
    
    // Get the string matches 
    $content = $match->getMatchingContent();
    
    // Get any additional metadata about the maches, e.g. Credit card number type like Visa
    $data = $match->getData();
}

$manager = new \SME\ContentDetectors\DetectionManager();

// Get the enabled detectors
$detectors = $manager->getDetectors();

// Disable a detector
$manager->disableDetector(\SME\ContentDetectors\Detectors\UKPhoneNumber::class);

// Enable a detector 
$manager->enableDetector(\SME\ContentDetectors\Detectors\UKPhoneNumber::class);

public function getRegularExpression()
{
    return '/\b((\d[ -]*){13,19})\b/um';
}

public function validateMatch($match)
{
    $info = GenericCreditCardValidator::validCreditCard($match);

    if(is_array($info) && array_key_exists('valid', $info) && $info['valid'] !== true) {
        return false;
    }

    $result = new Match();
    $result->setMatchType(self::class)
        ->setMatchingContent($match)
        ->setData([
            'type' => $info['type']
        ]);

    return $result;
}