imap_rfc822_parse_adrlist

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_rfc822_parse_adrlistアドレス文字列を解釈します

説明

imap_rfc822_parse_adrlist(string $string, string $default_hostname): array

» RFC2822 の定義に基づき、アドレス文字列をパースします。

パラメータ

string

アドレスを含む文字列。

default_hostname

デフォルトのホスト名。

戻り値

オブジェクトの配列を返します。オブジェクトのプロパティは以下のとおりです。

  • mailbox - メールボックス名(ユーザー名)。
  • host - ホスト名。
  • personal - 個人名。
  • adl - ドメインソースルート。

例1 imap_rfc822_parse_adrlist() の例

<?php

$address_string
= "Joe Doe <[email protected]>, [email protected], root";
$address_array = imap_rfc822_parse_adrlist($address_string, "example.com");
if (!
is_array($address_array) || count($address_array) < 1) {
die(
"something is wrong\n");
}

foreach (
$address_array as $id => $val) {
echo
"# $id\n";
echo
" mailbox : " . $val->mailbox . "\n";
echo
" host : " . $val->host . "\n";
echo
" personal: " . $val->personal . "\n";
echo
" adl : " . $val->adl . "\n";
}
?>

上の例の出力は以下となります。

# 0
  mailbox : doe
  host    : example.com
  personal: Joe Doe
  adl     : 
# 1
  mailbox : postmaster
  host    : example.com
  personal: 
  adl     : 
# 2
  mailbox : root
  host    : example.com
  personal: 
  adl     :

参考

add a note

User Contributed Notes 2 notes

up
1
Rainer Perske
20 years ago
Invalid addresses, if detected, set host to '.SYNTAX-ERROR.'; but not all invalid addresses get detected as such, e.g. <[email protected]> is considered
valid though a single dot is not a valid local part without using quotation marks.
up
0
marcrbarker at gmail dot com
3 days ago
Since PHP 8 giving NULL as an input address to parameter #1, it will now trigger the "PHP Deprecated: .... " warning (& in error_log if set up).
To Top