wppaste
WordPress

PHPMailer::parseSimplerAddresses( string $addrstr, string $charset ): array

Source
wp-includes/PHPMailer/PHPMailer.php:1353
Parse a string containing one or more RFC822-style comma-separated email addresses with the form "display name " into an array of name/address pairs.

Description

Uses a simpler parser that does not require the IMAP extension but doesnt support the full RFC822 spec. For full RFC822 support, use the PHP IMAP extension.

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$addrstrstring
The address list string
$charsetstring
The charset to use when decoding the address list string.

Return value

array

Performance profile

How much work a call to PHPMailer::parseSimplerAddresses() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
18–19

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 56.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost PHPMailer::parseSimplerAddresses() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always18–19::lang(), trigger_error(), explode()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5618–195
8.55618–195
8.45618–1958 fewer instructions than PHP 8.3
8.36418–195
8.26418–195
8.16418–195
7.46418–195

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 4

  • \PHPMailer\PHPMailer\PHPMailer::lang()
  • static::validateAddress()
  • static::parseEmailString()
  • static::decodeHeader()

Source code

    protected static function parseSimplerAddresses($addrstr, $charset)    {        // Emit a runtime notice to recommend using the IMAP extension for full RFC822 parsing        trigger_error(self::lang('imap_recommended'), E_USER_NOTICE);         $addresses = [];        $list = explode(',', $addrstr);        foreach ($list as $address) {            $address = trim($address);            //Is there a separate name part?            if (strpos($address, '<') === false) {                //No separate name, just use the whole thing                if (static::validateAddress($address)) {                    $addresses[] = [                        'name' => '',                        'address' => $address,                    ];                }            } else {                $parsed = static::parseEmailString($address);                $email = $parsed['email'];                if (static::validateAddress($email)) {                    $name = static::decodeHeader($parsed['name'], $charset);                    $addresses[] = [                        //Remove any surrounding quotes and spaces from the name                        'name' => trim($name, '\'" '),                        'address' => $email,                    ];                }            }        }         return $addresses;    }

Changelog

Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/PHPMailer/PHPMailer.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.