PHP code example of choval / email_parse

1. Go to this page and download the library: Download choval/email_parse 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/ */

    

choval / email_parse example snippets


$parts = email_parse('[email protected]');
var_dump($parts);
/*
array(11) {
  ["raw"]=>
  string(16) "[email protected]"
  ["unicode"]=>
  bool(false)
  ["valid"]=>
  bool(true)
  ["idn_domain"]=>
  string(11) "example.com"
  ["idn_local"]=>
  string(4) "user"
  ["idn_tld"]=>
  string(3) "com"
  ["domain"]=>
  string(11) "example.com"
  ["tld"]=>
  string(3) "com"
  ["local"]=>
  string(4) "user"
  ["safe_email"]=>
  string(16) "[email protected]"
  ["email"]=>
  string(16) "[email protected]"
}
*/

// Go crazy
$parts = email_parse('πŸ˜ƒ@ν…ŒμŠ€νŠΈγ€‚γƒ†γ‚Ήγƒˆ');
var_dump($parts);
/*
array(11) {
  ["raw"]=>
  string(26) "πŸ˜ƒ@ν…ŒμŠ€νŠΈγ€‚γƒ†γ‚Ήγƒˆ"
  ["unicode"]=>
  bool(true)
  ["valid"]=>
  bool(true)
  ["idn_domain"]=>
  string(25) "xn--9t4b11yi5a.xn--zckzah"
  ["idn_local"]=>
  string(8) "xn--h28h"
  ["idn_tld"]=>
  string(10) "xn--zckzah"
  ["domain"]=>
  string(19) "ν…ŒμŠ€νŠΈ.γƒ†γ‚Ήγƒˆ"
  ["tld"]=>
  string(9) "γƒ†γ‚Ήγƒˆ"
  ["local"]=>
  string(4) "πŸ˜ƒ"
  ["safe_email"]=>
  string(34) "[email protected]"
  ["email"]=>
  string(24) "πŸ˜ƒ@ν…ŒμŠ€νŠΈ.γƒ†γ‚Ήγƒˆ"
}
*/

$valid = email_valid('πŸ˜ƒ@ν…ŒμŠ€νŠΈγ€‚γƒ†γ‚Ήγƒˆ');
var_dump($valid);
// string(24) "πŸ˜ƒ@ν…ŒμŠ€νŠΈ.γƒ†γ‚Ήγƒˆ"

// Non valid because of starting dot
$valid = email_valid('.πŸ˜ƒ@ν…ŒμŠ€νŠΈ.γƒ†γ‚Ήγƒˆ');
var_dump($valid);
// bool(false)

$valid = email_safe('πŸ˜ƒ@ν…ŒμŠ€νŠΈγ€‚γƒ†γ‚Ήγƒˆ');
var_dump($valid);
// string(34) "[email protected]"

// Non valid because of starting dot
$valid = email_safe('.πŸ˜ƒ@ν…ŒμŠ€νŠΈ.γƒ†γ‚Ήγƒˆ');
var_dump($valid);
// bool(false)