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: Changed license to Apache License, Version 2.0.
Date: 1 month ago
Size: 1,187 bytes
 

Contents

Class file image Download
<?php

// 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>';
}