php从txt文件中分解新行内容
我有一个 txt 文件,其中的电子邮件地址位于另一个文件下,例如:
[email protected] [email protected]
到目前为止,我设法用以下命令打开它
$result = file_get_contents("tmp/emails.txt");but I don't know to to get the email addresses in an array. Basically I could use explode but how do I delimit the new line ? thanks in advance for any answer !
I have txt file with email addresses under under the other like :
[email protected] [email protected]
So far I managed to open it with
$result = file_get_contents("tmp/emails.txt");
but I don't know to to get the email addresses in an array. Basically I could use explode but how do I delimit the new line ?
thanks in advance for any answer !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需使用
file()
读取文件您将得到一个包含文件每一行的数组。要不向每个电子邮件地址附加换行符,请使用
FILE_IGNORE_NEW_LINES
标志,要跳过空行,请使用FILE_SKIP_EMPTY_LINES
标志:执行
var_dump($emails)<第二个示例的 /code> 给出了以下内容:
Just read the file using
file()
and you'll get an array containing each line of the file.To not append newlines to each email address, use the
FILE_IGNORE_NEW_LINES
flag, and to skip empty lines, use theFILE_SKIP_EMPTY_LINES
flag:Doing a
var_dump($emails)
of the second example gives this:尽管这看起来很疯狂,但在双引号 (
""
) 内执行return
或enter
会分隔换行符。为了清楚起见,输入:并只需在
""
中间按回车键,即可得到:并且它可以工作。可能是非常规的,并且可能只适用于 Linux。但它有效。
As crazy as this seems, doing a
return
orenter
inside a double-quote (""
) delimits a newline. To make it clear, type in:and simply hit return at the middle of
""
, so you get:and it works. Probably unconventional, and might only work on Linux. But it works.