First name|All|01.01.55.41
Second name||01.01.55.41
Third name||01.01.55.41
我正在尝试:
function get_content() {
$mailGeteld = NULL;
$mailGeteld = file_get_contents("content.txt");
$mailGeteld = explode("|",$mailGeteld);
return $mailGeteld[0];
}
但是现在我只得到“名字”,我怎么能循环呢,结果如下:
First name, Second name, Third name
解决方法:
function get_content() {
$firstWords = array();
$file = file("content.txt"); //read file line by line
foreach ($file as $val) {
if (trim($val) != '') { //ignore empty lines
$expl = explode("|", $val);
$firstWords[] = $expl[0]; //add first word to the stack/array
}
}
return $firstWords; //return the stack of words - thx furas ;D
}
echo implode(', ', get_content()); //puts a comma and a blankspace between each collected word
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。