QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1176|回复: 4

取2个字符中间的,请问咋写? (php)

[复制链接]
发表于 2004-11-14 21:14:18 | 显示全部楼层 |阅读模式
我的list文件是这样的
(*[email protected]/)
end
(*[email protected]/)
end
(*[email protected]/)
end
(*[email protected]/)
end
(*[email protected]/)
end

end if



我想只把每段的邮件地址取出来
请问我该咋写代码?
发表于 2004-11-15 20:10:11 | 显示全部楼层
最好去除文件后部的end if.会使工作方便一点。
我试着做一个循环
[code:1]$file=fopen("file");
for($c=0;!feof($file);$c++)
{
fseek($file,2,SEEK_CUR);
$mailaddr[c]=substr(fgets($file),0,-2);
}
do{echo current($mailaddr);}while(next($mailaddr));
fclose($file);
[/code:1]
但试运行失败 ,好像是循环不能跳出,没结果显示。
我这里没法进行调试,哪位好心人帮我看看
回复

使用道具 举报

 楼主| 发表于 2004-11-15 23:53:55 | 显示全部楼层
[quote:7a17fbb400="neptune"][code:1]$file=fopen("file");
for($c=0;!feof($file);$c++)
{
fseek($file,2,SEEK_CUR);
$mailaddr[c]=substr(fgets($file),0,-2);
}
do{echo current($mailaddr);}while(next($mailaddr));
fclose($file);
[/code:1]
[/quote]
------------------------------------------------------------------------
这样修改就好了:
$handle="文件名字";
$fp=array();
$fp=file("$handle");
for ($c=0;$c<count($fp);$c=$c+2)
{
$mailaddr[$c]=substr($fp[$c],13,-4);
}
do{echo current($mailaddr);}while(next($mailaddr));
--------------------------------------------------------------------------
但是请问如下代码,怎样实现输出一个变量就换行?
do{echo current($mailaddr);}while(next($mailaddr));
回复

使用道具 举报

发表于 2004-11-16 19:51:17 | 显示全部楼层
[code:1]echo current($mailaddr)."<br>";
[/code:1]行吗?
回复

使用道具 举报

发表于 2004-11-17 13:29:43 | 显示全部楼层
ok
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-28 08:24 , Processed in 0.137627 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表