如何从echo输出中删除单个电子邮件地址?

时间:2014-08-16 03:42:40

标签: php

我只想从脚本输出中删除电子邮件地址。我到处搜索,似乎与我的剧本无关。例如,如何从echoed输出中删除user@domain.com?

<?
$dat = file_get_contents('webhook.dat');
$dat .= "\n" . file_get_contents('webhook1.dat');
$dat .= "\n" . file_get_contents('webhook2.dat');
$fp = fopen('webhookmerge.dat', 'w');
if(!$fp)
  die('Could not create / open data file for writing.');
if(fwrite($fp, $dat) === false)
  die('Could not write to data file.'); 
?>

<?
$file = "webhookmerge.dat";
$text=file_get_contents($file);
$res = preg_match_all(
  "/[a-z0-9]+[_a-z0-9\.-]*[a-z0-9]+@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})/i",
  $text, $matches);
sort($matches[0]);
if ($res) {
  foreach(array_unique($matches[0]) as $email) {
    echo "<b><font color='black' face='arial' size='2pt'>$email</font></b>" . "<br />";
  }
}
else {
  echo "No emails found.";
}
?>

1 个答案:

答案 0 :(得分:0)

为避免打印某些字符串,您可以在echo命令之前添加检查:

foreach(array_unique($matches[0]) as $email) {
  if ($email != "user@domain.com") {
    echo "<b><font color='black' face='arial' size='2pt'>$email</font></b><br />";
  }
}