Login   Register  
PHP Classes
elePHPant
Icontem

File: example-2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Peter Kahl  >  Extract Name from Email Address  >  example-2.php  >  Download  
File: example-2.php
Role: Example script
Content type: text/plain
Description: Process multiple addresses
Class: Extract Name from Email Address
Extract person name from e-mail address header
Author: By
Last change: Added method for email address extraction. Bug fix.
Date: 9 months ago
Size: 1,512 bytes
 

Contents

Class file image Download
<?php

/**
 *
 * Name Extractor
 * Version:      1.2.0
 * Last Updated: 2013-11-05
 * Copyright (c) 2012-2013 Peter Kahl. All rights reserved. www.colossalmind.com
 * Use of this source code is governed by a GNU General Public License
 * that can be found in the enclosed documentation.
 *
 * https://github.com/peterkahl/name-extractor
 *
 */

// Extract name/email from batch (array) of email address headers

function my_encode($str) {
    
$preferences = array(
        
"input-charset" => "UTF-8",
        
"output-charset" => "UTF-8",
        
"line-length" => 76,
        
"line-break-chars" => "\n",
        
"scheme" => "B"
    
);
    
$enc iconv_mime_encode("From"$str$preferences);
    list(
$w$name) = explode(': '$enc);
    return 
$name;
}

require 
dirname(__FILE__).'/class.name-extractor.php';

$cmname = new name_extractor();

$emails = array(
    
'Kickstarter<no-reply@kickstarter.com>',
    
'"Pretty Kitty"<qwerty@some.tld>',
    
'johnbutterworth@gmail.com',
    
'andreasschmid@yahoo.com',
    
'paul.martin@hotmail.com',
    
'steve jobs <73fh3y4svbcgd@apple.com>',
    
'cameronsweeney@domain.tld <csweeney@domain.tld>',
    
'JoeWilson@Division <joe123@company.tld>',
    
'=?iso-2022-jp?B?GyRCS1EbKEIgGyRCSH5JMRsoQiA=?= <blah@foo.co.jp>',
    
my_encode('Серге́й Льво́вич Со́болев').' <blah@mail.ru>',
    
my_encode('高錕').' <kao@bar.com.hk>'
    
);

foreach (
$emails as $val) {
    echo 
htmlspecialchars($val).' --> '.$cmname->extract_name($val).' --> '.$cmname->extract_addr($val).'<br />';
}