Php 提取一些电子邮件

Php 提取一些电子邮件,php,regex,Php,Regex,我有这样的想法: test<test@test.com>, test1<test1@test.com>,test2<test2@test.com> 结果$email:我有testtest@test.com而不是 test@test.com 然后,您可以创建、调用和使用以下函数 <?php function stripText($text){ $lesspos=stripos($text,"<")+1;

我有这样的想法:

test<test@test.com>, test1<test1@test.com>,test2<test2@test.com>
结果
$email
:我有
testtest@test.com
而不是

test@test.com

然后,您可以创建、调用和使用以下函数

<?php
    function stripText($text){
        $lesspos=stripos($text,"<")+1;//finding the position of < and set the start of substring by adding one
        $greatpos=stripos($text,">")+1;//finding the position of >
        $length=strlen($text)-$lesspos-$greatpos;//length of the string between the two symbol
        $stripedtext=substr($text,$lesspos,$length);//striping the text we need out
        return $stripedtext;//returning the striped text
    }
    $text="test<test@example.com>";
    echo stripText($text);
?>

您可以创建、调用和使用以下函数

<?php
    function stripText($text){
        $lesspos=stripos($text,"<")+1;//finding the position of < and set the start of substring by adding one
        $greatpos=stripos($text,">")+1;//finding the position of >
        $length=strlen($text)-$lesspos-$greatpos;//length of the string between the two symbol
        $stripedtext=substr($text,$lesspos,$length);//striping the text we need out
        return $stripedtext;//returning the striped text
    }
    $text="test<test@example.com>";
    echo stripText($text);
?>

要匹配示例字符串的电子邮件地址,可以使用捕获组和
\G
锚点在匹配字符串的第一部分后获得连续匹配

(?:[^\s<>]+<|\G(?!^))([^\s@<>]+@[^\s@<>]+)>(?:,\h*|$)
输出

Array
(
    [0] => test@test.com
    [1] => test1@test.com
    [2] => test2@test.com
)

要匹配示例字符串的电子邮件地址,可以使用捕获组和
\G
锚点在匹配字符串的第一部分后获得连续匹配

(?:[^\s<>]+<|\G(?!^))([^\s@<>]+@[^\s@<>]+)>(?:,\h*|$)
输出

Array
(
    [0] => test@test.com
    [1] => test1@test.com
    [2] => test2@test.com
)
这能帮助您:

$pattern = '/(?<=<)(.*?)+(?=\>)/';
$string = 'test<test@test.com>, test1<test1@test.com>,test2<test2@test.com>';
preg_match_all($pattern , $string , $emails);
var_dump($emails[0]);
这能帮助您:

$pattern = '/(?<=<)(.*?)+(?=\>)/';
$string = 'test<test@test.com>, test1<test1@test.com>,test2<test2@test.com>';
preg_match_all($pattern , $string , $emails);
var_dump($emails[0]);
/(?
/)?