PHP code example of thedomeffm / email-canonicalizer
1. Go to this page and download the library: Download thedomeffm/email-canonicalizer 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/ */
thedomeffm / email-canonicalizer example snippets
use TheDomeFfm\EmailCanonicalizer\EmailCanonicalizer;
use TheDomeFfm\EmailCanonicalizer\Exception\InvalidEmailException;
$canonicalizer = EmailCanonicalizer::default(); // all public mail providers, then the lowercase fallback
try {
$canonicalEmail = $canonicalizer->canonicalize(' [email protected] ');
} catch (InvalidEmailException $exception) {
// not a valid email address
}
// MissingExtensionException (a LogicException) is only thrown for internationalized domains without ext-intl.
$canonicalEmail->email(); // "[email protected]", store this to detect duplicate accounts
$canonicalEmail->original; // " [email protected] "
$canonicalEmail->provider?->name(); // "gmail"
use TheDomeFfm\EmailCanonicalizer\Matcher\ExactDomainMatcher;
use TheDomeFfm\EmailCanonicalizer\Provider\GenericProvider;
use TheDomeFfm\EmailCanonicalizer\Provider\GmailProvider;
use TheDomeFfm\EmailCanonicalizer\Provider\LowercaseProvider;
use TheDomeFfm\EmailCanonicalizer\PublicMailProviders;
use TheDomeFfm\EmailCanonicalizer\Rule\SubaddressRule;
EmailCanonicalizer::default(); // public mail providers, then lowercase fallback
// your own provider in front of the defaults
EmailCanonicalizer::default(
new GenericProvider('our-business', new ExactDomainMatcher('example.com'), new SubaddressRule('-')),
);
// only the providers you pass
new EmailCanonicalizer(new GmailProvider(), new LowercaseProvider());
new EmailCanonicalizer(...new PublicMailProviders()); // known providers only, other domains keep their local part as it is
EmailCanonicalizer::lowercaseOnly(); // only trim and lowercase
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.