我通过此语句得到以下输出
$varname = file_get_contents('php://input');
输出-
You've got a new submission8793892-1=AM+BH&8793892-2=TT&8793893=aman.h340gmail.com&8793894=005-222-2222&8793895=&8793895-1=&8793895-2=&8793895-3=&8793895-4=&8793895-5=&8793895-6=India&8793896=Standard+%28%2430%2Fmonth%29&8793897_0=no&8793897_1=no&8793897_2=no&8793897_3=no&8793897_4=no&8793897_5=no&8793898=&8793899_0=yes&8793900=No&submissionHtml=&entryId=24&submissionId=x5e417c6eae46d8.13907951&geoipcache=%7B%223753571910%22%3A%7B%22ip_ctry%22%3A%22IN%22%2C%22ip_cntry%22%3A%22IND%22%2C%22ip_country%22%3A%22India%22%7D%7D&dateTime=2020-02-10+11%3A53%3A18&sessionGlobalsVars%5Bu_timezone%5D=-4&sessionGlobalsVars%5Bf_refon%5D=0&sessionGlobalsVars%5Bf_adduserinfo%5D=1&sessionGlobalsVars%5Brefid_timestamp%5D=1581349998&sessionGlobalsVars%5Btimestamp%5D=2020-02-10+11%3A53&sessionGlobalsVars%5Bgdrive_sender%5D=noreply%40app.captainform.com&sessionGlobalsVars%5Bgdrive_to%5D=annasawin%40gmail.com&sessionGlobalsVars%5Bgdrive_contact_email%5D=support%40123contactform.com&ses sionGlob
我只想提取电子邮件ID,如何获取?我尝试了所有可能的方法,但没有成功。尝试过,但没有成功,任何人都可以帮助..谢谢
$array=json_decode($varname,true);
$array["8793893"];
答案 0 :(得分:2)
使用parse_str()
函数:
$varname = "You've got a new submission8793892-1=AM+BH&8793892-2=TT&8793893=aman.h340gmail.com&8793894=005-222-2222&8793895=&8793895-1=&8793895-2=&8793895-3=&8793895-4=&8793895-5=&8793895-6=India&8793896=Standard+%28%2430%2Fmonth%29&8793897_0=no&8793897_1=no&8793897_2=no&8793897_3=no&8793897_4=no&8793897_5=no&8793898=&8793899_0=yes&8793900=No&submissionHtml=&entryId=24&submissionId=x5e417c6eae46d8.13907951&geoipcache=%7B%223753571910%22%3A%7B%22ip_ctry%22%3A%22IN%22%2C%22ip_cntry%22%3A%22IND%22%2C%22ip_country%22%3A%22India%22%7D%7D&dateTime=2020-02-10+11%3A53%3A18&sessionGlobalsVars%5Bu_timezone%5D=-4&sessionGlobalsVars%5Bf_refon%5D=0&sessionGlobalsVars%5Bf_adduserinfo%5D=1&sessionGlobalsVars%5Brefid_timestamp%5D=1581349998&sessionGlobalsVars%5Btimestamp%5D=2020-02-10+11%3A53&sessionGlobalsVars%5Bgdrive_sender%5D=noreply%40app.captainform.com&sessionGlobalsVars%5Bgdrive_to%5D=annasawin%40gmail.com&sessionGlobalsVars%5Bgdrive_contact_email%5D=support%40123contactform.com&ses sionGlob";
parse_str($varname, $array);
var_dump($array);
这将为您提供所需的输出:
array(28) {
["You've_got_a_new_submission8793892-1"]=>
string(5) "AM BH"
["8793892-2"]=>
string(2) "TT"
[8793893]=>
string(18) "aman.h340gmail.com"
[8793894]=>
string(12) "005-222-2222"
[8793895]=>
string(0) ""
["8793895-1"]=>
string(0) ""
["8793895-2"]=>
string(0) ""
["8793895-3"]=>
string(0) ""
["8793895-4"]=>
string(0) ""
["8793895-5"]=>
string(0) ""
["8793895-6"]=>
string(5) "India"
[8793896]=>
string(20) "Standard ($30/month)"
["8793897_0"]=>
string(2) "no"
["8793897_1"]=>
string(2) "no"
["8793897_2"]=>
string(2) "no"
["8793897_3"]=>
string(2) "no"
["8793897_4"]=>
string(2) "no"
["8793897_5"]=>
string(2) "no"
[8793898]=>
string(0) ""
["8793899_0"]=>
string(3) "yes"
[8793900]=>
string(2) "No"
["submissionHtml"]=>
string(0) ""
["entryId"]=>
string(2) "24"
["submissionId"]=>
string(24) "x5e417c6eae46d8.13907951"
["geoipcache"]=>
string(69) "{"3753571910":{"ip_ctry":"IN","ip_cntry":"IND","ip_country":"India"}}"
["dateTime"]=>
string(19) "2020-02-10 11:53:18"
["sessionGlobalsVars"]=>
array(8) {
["u_timezone"]=>
string(2) "-4"
["f_refon"]=>
string(1) "0"
["f_adduserinfo"]=>
string(1) "1"
["refid_timestamp"]=>
string(10) "1581349998"
["timestamp"]=>
string(16) "2020-02-10 11:53"
["gdrive_sender"]=>
string(27) "noreply@app.captainform.com"
["gdrive_to"]=>
string(19) "annasawin@gmail.com"
["gdrive_contact_email"]=>
string(26) "support@123contactform.com"
}
["ses_sionGlob"]=>
string(0) ""
}
答案 1 :(得分:0)
您的输入字符串的格式类似于a query string-使用此事实(如果在所有情况下都是事实),并且您知道电子邮件存储在哪个密钥中(在您的情况下为{{ 1}}),那么您可以使用parse_str()函数来解析字符串:
8793893
但是,如果您不知道它们的键和/或键是动态的,则必须遍历数组并查找结构类似于电子邮件的值。 PHP有一个非常方便的filter_var()函数,用于验证字符串:
$varname = "You've got a new submission8793892-1=AM+BH&8793892-2=TT&8793893=aman.h340gmail.com&8793894=005-222-2222&8793895=&8793895-1=&8793895-2=&8793895-3=&8793895-4=&8793895-5=&8793895-6=India&8793896=Standard+%28%2430%2Fmonth%29&8793897_0=no&8793897_1=no&8793897_2=no&8793897_3=no&8793897_4=no&8793897_5=no&8793898=&8793899_0=yes&8793900=No&submissionHtml=&entryId=24&submissionId=x5e417c6eae46d8.13907951&geoipcache=%7B%223753571910%22%3A%7B%22ip_ctry%22%3A%22IN%22%2C%22ip_cntry%22%3A%22IND%22%2C%22ip_country%22%3A%22India%22%7D%7D&dateTime=2020-02-10+11%3A53%3A18&sessionGlobalsVars%5Bu_timezone%5D=-4&sessionGlobalsVars%5Bf_refon%5D=0&sessionGlobalsVars%5Bf_adduserinfo%5D=1&sessionGlobalsVars%5Brefid_timestamp%5D=1581349998&sessionGlobalsVars%5Btimestamp%5D=2020-02-10+11%3A53&sessionGlobalsVars%5Bgdrive_sender%5D=noreply%40app.captainform.com&sessionGlobalsVars%5Bgdrive_to%5D=annasawin%40gmail.com&sessionGlobalsVars%5Bgdrive_contact_email%5D=support%40123contactform.com&ses sionGlob";
$array = [];
parse_str($varname, $array);
echo $array['8793893'];
请记住,您问题所在的原始字符串中的电子邮件地址格式不正确。因此,filter / regex无法识别它。