我在搜索字符串时遇到了一些问题。我正在使用cPanel中的XMLAPI列出我的cPanel上的所有电子邮件帐户。然后,我想用列表中的内容搜索用户的输入,以查看电子邮件是否已存在。但问题是:
如果新电子邮件是1个字母,例如:1@domain.com
如果列表中的1个电子邮件结束且编号为1 - > josh1@domain.com,搜索会说1 @domain.com在列表中。
这是列表的样子:
{
"cpanelresult": {
"event": {
"result": 1
},
"data": [{
"email": "1@domain.com",
"login": "1@domain.com"
}, {
"email": "10@domain.com",
"login": "10@domain.com"
}, {
"email": "11@domain.com",
"login": "11@domain.com"
}, {
"email": "5@domain.com",
"login": "5@domain.com"
}, {
"email": "8@domain.com",
"login": "8@domain.com"
}, {
"email": "9@domain.com",
"login": "9@domain.com"
}, {
"email": "admin@domain.com",
"login": "admin@domain.com"
}, {
"email": "auth@domain.com",
"login": "auth@domain.com"
}, {
"email": "cai@domain.com",
"login": "cai@domain.com"
}, {
"email": "estoris@domain.com",
"login": "estoris@domain.com"
}, {
"email": "johndoe@domain.com",
"login": "johndoe@domain.com"
}, {
"email": "maplex111@domain.com",
"login": "maplex111@domain.com"
}, {
"email": "**maplex222@domain.com**",
"login": "maplex222@domain.com"
}, {
"email": "patrickroxs@domain.com",
"login": "patrickroxs@domain.com"
}, {
"email": "test@domain.com",
"login": "test@domain.com"
}, {
"email": "amail",
"login": "Main
Account"
}],
"func": "listpops",
"module": "Email",
"apiversion": 2
}
}
这就是我尝试找到电子邮件所做的:
if(preg_match("/2@domain.com/",$try) == true) {
echo 'Found the email!';
} else {
echo 'Did not find email';
}
该代码表示电子邮件在列表中,而不是。那我该怎么做呢?
答案 0 :(得分:0)
你没有匹配双引号。
if(preg_match('/"' + email + '"/',$try) == true) {
echo 'Found the email!';
} else {
echo 'Did not find email';
}