我有一个txt文件和PHP我需要收到email1@gmail.com和email2@gmail.com我该怎么办?
我有2天的时间搜索解决方案,但我找不到它。
我试过这个但是没有工作:
$filedata = file_get_contents("file.txt");
preg_match_all('~^Email:(.*)$~m', $filedata, $matches);
foreach ($matches[1] as $clave=>$result_email)
{
if ($stmt = $mysqli->prepare("SELECT name, email, pass FROM table_bd WHERE email=? ")) {
$stmt->bind_param('s', $result_email);
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
if ($stmt->num_rows ==1) {
// get variables from result.
$stmt->bind_result($name, $email, $pass);
$stmt->fetch();
}
}
echo $name.":".$pass."<br/>";
}
&#13;
我有这个txt文件:
#name,email/username,password,description,unique name,email validation username
"lyndia.easda,geasdsadrs,,234342:4344,rocasda34,TasdadL,,01/01/1900,"""
Username:user1
Biography:
UserId:6333
Email:email1@gmail.com
PhoneNumber:+82234614
"Original number::325 /5ersion/6.0 Mobile/10B350 Safari/8536.25"""
"asdasd.985,asd34e3,,456465:6573,rocsdad7,023sa,,01/01/1900,"""
Username:user2
Biography:
UserId:392347703
Email:email2@gmail.com
PhoneNumber:+823werrs
答案 0 :(得分:1)
strpos()
会返回FALSE
或0
。它有所不同:FALSE
如果找不到,0
在索引0。
您必须使用strict equality来检查它是否为假或0:
if (strpos($line, $word) !== false)
输出:
Word find: Email: 8
Word find: Email: 19
另一种获取电子邮件的方式:
$filedata = file_get_contents("file.txt");
preg_match_all('~^Email:(.*)$~m', $filedata, $matches);
print_r($matches[1]);
输出:
Array
(
[0] => example1@gmail.com
[1] => example2@gmail.com
)
答案 1 :(得分:0)
您可以使用explode()将电子邮件值设为
if (strpos($line, $word) !== false) {
$email_array = explode(":",fgets($line));
$email_array[1];//this will give you email id
echo "<p>Word find: <b> $email_array[1]</b></p>";
echo $line_count;
}