本文整理汇总了PHP中Contao\StringUtil::extractEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::extractEmail方法的具体用法?PHP StringUtil::extractEmail怎么用?PHP StringUtil::extractEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contao\StringUtil
的用法示例。
在下文中一共展示了StringUtil::extractEmail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExtractEmail
/**
* Tests the StringUtil::extactEmail() method.
*/
public function testExtractEmail()
{
$text = <<<EOF
This is a niceandsimple@example.com and this a very.common@example.com. Another little.lengthy.but.fine@dept.example.com and also a disposable.style.email.with+symbol@example.com or an other.email-with-dash@example.com. There are "very.unusual.@.unusual.com"@example.com and "very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"@strange.example.com and even !#\$%&'*+-/=?^_`{}|~@example.org or "()<>[]:,;@\\"!#\$%&'*+-/=?^_`{}|~.a"@example.org but they are all valid.
IP addresses as in user@[255.255.255.255], user@[IPv6:2001:db8:1ff::a0b:dbd0], user@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344], user@[IPv6:2001::7344] or user@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255] are valid, too.
We also support IDNA domains as in test@exämple.com, test@ä-.xe, test@subexample.wizard, test@wähwähwäh.ümläüts.de or "tes@t"@wähwähwäh.ümläüts.de. And we support new TLDs as in test@example.photography or test@sub-domain.example.photography.
And we support unicode characters in the local part (RFC 6531) as in niceändsimple@example.com, véry.çommon@example.com, a.lîttle.lengthy.but.fiñe@dept.example.com, dîsposable.style.émail.with+symbol@example.com, other.émail-with-dash@example.com, "verî.uñusual.@.uñusual.com"@example.com, "verî.(),:;<>[]\\".VERÎ.\\"verî@\\ \\"verî\\".unüsual"@strange.example.com, üñîçøðé@example.com, "üñîçøðé"@example.com or DžǼ੧ఘⅧ⒇৪@example.com.
Of course also with IP addresses: üser@[255.255.255.255], üser@[IPv6:2001:db8:1ff::a0b:dbd0], üser@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344], üser@[IPv6:2001::7344] or üser@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255] and unicode characters in the local part: tést@exämple.com, tést@ä-.xe, tést@subexample.wizard, tést@wähwähwäh.ümläüts.de, "tés@t"@wähwähwäh.ümläüts.de. New TLDs? No problem: tést@example.photography or tést@sub-domain.example.photography.
And hopefully we do not match invalid addresses such as test..child@example.com, test@sub.-example.com, test@_smtp_.example.com, test@sub..example.com, test@subexamplecom, Abc.example.com, a"b(c)d,e:f;gi[j\\k]l@example.com, this is"not\\allowed@example.com, this\\ still\\"not\\allowed@example.com, (comment)test@iana.org, test@[1.2.3.4, @ or test@.
EOF;
$expected = ['niceandsimple@example.com', 'very.common@example.com', 'little.lengthy.but.fine@dept.example.com', 'disposable.style.email.with+symbol@example.com', 'other.email-with-dash@example.com', '"very.unusual.@.unusual.com"@example.com', '"very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"@strange.example.com', '!#$%&\'*+-/=?^_`{}|~@example.org', '"()<>[]:,;@\\"!#$%&\'*+-/=?^_`{}|~.a"@example.org', 'user@[255.255.255.255]', 'user@[IPv6:2001:db8:1ff::a0b:dbd0]', 'user@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344]', 'user@[IPv6:2001::7344]', 'user@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', 'test@exämple.com', 'test@ä-.xe', 'test@subexample.wizard', 'test@wähwähwäh.ümläüts.de', '"tes@t"@wähwähwäh.ümläüts.de', 'test@example.photography', 'test@sub-domain.example.photography', 'niceändsimple@example.com', 'véry.çommon@example.com', 'a.lîttle.lengthy.but.fiñe@dept.example.com', 'dîsposable.style.émail.with+symbol@example.com', 'other.émail-with-dash@example.com', '"verî.uñusual.@.uñusual.com"@example.com', '"verî.(),:;<>[]\\".VERÎ.\\"verî@\\ \\"verî\\".unüsual"@strange.example.com', 'üñîçøðé@example.com', '"üñîçøðé"@example.com', 'DžǼ੧ఘⅧ⒇৪@example.com', 'üser@[255.255.255.255]', 'üser@[IPv6:2001:db8:1ff::a0b:dbd0]', 'üser@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344]', 'üser@[IPv6:2001::7344]', 'üser@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', 'tést@exämple.com', 'tést@ä-.xe', 'tést@subexample.wizard', 'tést@wähwähwäh.ümläüts.de', '"tés@t"@wähwähwäh.ümläüts.de', 'tést@example.photography', 'tést@sub-domain.example.photography'];
$actual = StringUtil::extractEmail($text);
sort($actual);
sort($expected);
$this->assertEquals($expected, $actual);
}