查看: 7524|回复: 0
打印 上一主题 下一主题

用PHP将数据导入到Foxmail

[复制链接]
跳转到指定楼层
1#
发表于 2007-9-6 10:51:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
<title>Exceed PHP - 用PHP将数据导入到Foxmail</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="description" content="用PHP将数据导入到Foxmail">
<meta name="keywords" content="用PHP将数据导入到Foxmail">
<meta name="author" content="大A(avenger#php.net).">
<link href="/templates/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript">
var currentpos,timer;

function initialize()
{
timer=setInterval("scrollwindow()",2);
}
function sc(){
clearInterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrollTop;
window.scroll(0,++currentpos);
if (currentpos != document.body.scrollTop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
</script>
</head>

<body>


<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#328D3A">
<tr>
  <td><img src="/images/spacer.gif" width="1" height="5" alt=""></td>
   <td width="5" bgcolor="#32853A"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>

<!-- NAV BAR BEGIN -->
<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#397D3E">
<tr>
  <td width="222"><a href="/"><img src="/inc/logo.php" width="222" height="57" border="0" alt="超越PHP"></a></td>
  <td align="right" valign="bottom">
   <a href="/?n=News" title="News"><span class="cn1">PHP动态</span></a>
    <font class="en1"> | </font> <a href="/?n=Articles" title="Articles"><span class="cn1"> 经典文章</span></a>
    <font class="en1"> | </font> <a href="/?n=Classes" title="Classes"><span class="cn1"> CLASS</span></a>
    <font class="en1"> | </font> <a href="/?n=Download" title="Downloads"><span class="cn1"> 相关下载</span></a>
    <font class="en1"> | </font> <a href="/?n=Faq" title="F & Q"><span class="cn1"> 常见问题</span></a>
    <font class="en1"> | </font> <a href="/?n=Forum" title="Forum"><span class="cn1"> FORUM</span></a>
    <font class="en1"> | </font> <a href="/?n=Wiki" title="Wiki"><span class="cn1"> WIKI</span></a>
    <font class="en1"> | </font> <a href="/?n=Manual" title="Online Manual"><span class="cn1">在线手册</span></a>
    </td>
   <td width="5" bgcolor="#39753E"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>
<!-- NAV BAR END -->


<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
  <td><img src="/images/spacer.gif" width="1" height="1" alt=""></td>
   <td width="5" bgcolor="#333333"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>

<!-- SEARCH BEGIN -->
<form name="search" method="get" action="/site_search.php">
<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#007770">
<tr>
  <td align="right" class="en1" valign="bottom">
    <font color="#FFFFFF" class="small">Site <u>s</u>earch:</font>
    <input name="search" type="text" class="en1" size="15" maxlength="20" value="" accesskey="s">
       <input name="submit" type="image" src="/images/submit.gif" alt="Search">
  </td>
   <td width="10"> </td>
   <td width="5" bgcolor="#006C70"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>
</form>
<!-- SEARCH END -->

<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
  <td><img src="/images/spacer.gif" width="1" height="1" alt=""></td>
   <td width="5" bgcolor="#333333"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>


<!-- MAIN TABLE START -->
<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
<tr>
  <td valign="top" colspan="3" bgcolor="#FEFEFE">
    <table align="CENTER" width="98%" border="0" cellspacing="8" cellpadding="4">
    <tr>
      <td><a href="/"><img border=0 src="/images/home_1.gif" alt="Home" align="absmiddle"></a> <a href="/">首页</a><b><span style='font-size: 7pt' lang='zh-cn'> &raquo; </span></b><a href='/?n=Articles'>经典文章</a><b><span style='font-size: 7pt' lang='zh-cn'> &raquo; </span></b> 文章查看</td>
    </tr>
    </table>
    <table align="CENTER" width="90%" border="0" cellspacing="0" cellpadding="1">
    <tr>
      <td align="CENTER" height="18"><h4>用PHP将数据导入到Foxmail</h4>
    <hr size=1>
    </td>
    </tr>
    <tr>
      <td> 作者:暖阳 来源:Pconline</td>
    </tr>
   <tr><td> </td></tr>
   <tr><td align=center>

<!-- Ads by Google -->
<script type="text/javascript"><!--
google_ad_client = "pub-2928087963304701";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_channel ="9725746080";
google_color_border = "666666";
google_color_bg = "FFFFFF";
google_color_link = "FF0000";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br /> <br />

   </td></tr>
   <tr>
      <td width=580 style="word-wrap:break-word; font-size: 14px; line-height: 160%"><P>     最近小阳做了一个PHP同学录,同学们自己在那里添加或修改姓名、邮箱、OICQ等信息,并保存在mySQL数据库里。某日小阳突然想到,如果能用PHP生成一个文件,供同学们下载并把这些资料导入他们的Foxmail地址簿中,那该多好啊!<BR> <BR>     说干就干,很快小阳便将这功能推出来了。那是如何实现的呢?这里仅以导出姓名、邮箱和OICQ三项予以说明。</P>

<P>     要资料可以导入Foxmail地址簿,当然要先了解一下导入Foxmail地址簿的文件内容和格式。打开Foxmail4.2一个帐户的地址簿,在其菜单栏“工具”-“导入”中可以看到,Foxmail支持两种外部文件的导入:“CSV文件”和“Wab文件”。我们选择生成CSV文件。那么可以导入Foxmail的CSV文件的内容和格式如何呢?让我们先从Foxmail导出一个CSV文件看一下。在Foxmail地址簿中选择一个记录不为空的文件夹,执行“工具”-“导出”- “文本文件”,保存文件名为“TEMP.CSV”, 在“下一步”的“请选择输出字段”中选择“姓名”、“电子邮箱地址”和“OICQ”,点击“完成”后便在指定路径生成了“TEMP.CSV”文件了。如果你装了微软office系列,会发现这是一个用EXCEL默认打开的文件,实际上它是EXCEL的逗号分隔值文件,双击打开后,其界面如图所示。</P>

<P><A href="/uploads/images/article_1042969533.gif" target=_blank><IMG alt=点击查看原图 hspace=3 src="/uploads/images/article_1042969533.gif" width=383 align=center vspace=3 border=0></A></P>

<P>     我们在这种情况下还是无法知道它的写入格式的。将“TEMP.CSV”文件改为用记事本打开,便可以发现它的格式非常简单:如图,文件第一行是Foxmail地址簿的字段,其它行是字段对应的值,各字段和值用英文逗号分隔。所以我们在PHP中按这种格式生成CSV文件,别人就可以下载并导入他们的Foxmail中了!</P>

<P><A href="/uploads/images/article_1042969619.gif" target=_blank><IMG alt=点击查看原图 hspace=3 src="/uploads/images/article_1042969619.gif" width=265 align=center vspace=3 border=0></A></P>

<P>     不过还有一个问题需要解决,那就是既然文件中以逗号作为分隔值,如果数据库记录中有英文逗号(注:以下符号若无特别说明皆指英文符号)怎么办?当然你可以先将数据中的逗号替换为中文逗号,但其实还有一个方法,那就是如果CSV文件相应的字段两端加上双引号(“即" "”)作分隔值,其间的英文逗号不作为分隔值,且字段中连续两个英文双引号(即“""”)也只作为一个显示,而不作为分隔值。</P>

<P>     有了这些认识,我们就可以编写导出CSV文件的PHP文件了:</P>

<P class=php><?<BR>//这一行一定要放在程序的开始地方,不能有空格或换行。因为下面的header()函数不允许在使用前向用户输出任何东西。 <BR>$dfname="tofoxmail.csv"; //生成的文件名<BR>//连接mySQL数据库:<BR>  mysql_connect("localhost","yourname","yourpassword") or die("不能连接数据库!");<BR>  mysql_select_db("alumni") or die("数据库发生错误!");<BR>if($action=="downit"){<BR>  $getdata=mysql_query("SELECT name,email,oicq FROM classdata"); //选择数据表中指定记录<BR>//如果没有资料,则:<BR>  if(@mysql_num_rows($getdata)==0){<BR>  echo "对不起,还没有任何资料!";<BR>  exit;<BR>  }<BR>  //以下生成一个文件供下载:<BR>  header("Content-disposition: filename=$dfname");<BR>  header("Content-type: unknown/unknown");<BR>  echo "姓名,电子邮件地址,OICQ,foxaddrID"; //输出第一行,Foxmail地址簿的字段<BR>  $i=1;<BR>  while($row=mysql_fetch_array($getdata)){ //取得数据类型的值<BR>  //将数据中每一个双引号替换为两个:<BR>  $row[name]=str_replace("\"","\"\"",$row[name]);<BR>  $row[email]=str_replace("\"","\"\"",$row[email]);<BR>  $row[oicq]=str_replace("\"","\"\"",$row[oicq]);<BR>  //输出相应字段对应的值的行,每个值用双引号和逗号作分隔符:<BR>  echo base64_decode("DQo=")."\"$row[name]\",\"$row[email]\",\"$row[oicq]\",$i";<BR>  /*上式中“base64_decode("DQo=")”是换行符,之所以不用“\n”,是因为两者不完全相同,<BR>  用后者将可能导致Foxmail导入失败。<BR>  */<BR>  $i++;<BR>  }<BR>  exit;<BR>  } <BR>  ? ><BR>  < !--如果不是点击了下载的链接,则显示以下HTML内容-- ><BR>  < html><BR>  < head> <BR>  < meta http-equiv="Content-Type" content="text/html; charset=gb2312"><BR>  < title>导出资料到Foxmail地址簿< /title>< /head><BR>  < body> 点击< a href=\'javascript:this.location=this.location+"?action=downit"\'>这里< /a>下载文件,保存并导入到您的Foxmail地址簿中。< br><BR>  < B>操作方法< /B>< br><BR>  …… <BR>  < /body><BR>  < /html></P>

<P>     在服务器上运行上述PHP文件,下载回来的“tofoxmail.csv”文件用记事本打开如图所示。</P>

<P>     在Foxmail地址簿中点击“工具”-“导入”-“CSV文件”……,数据库中一大堆的资料一下子就全被导入了,这个主意还不错吧!</P>

<P><A href="/uploads/images/article_1042969664.gif" target=_blank><IMG alt=点击查看原图 hspace=3 src="/uploads/images/article_1042969664.gif" width=299 align=center vspace=3 border=0></A></P>

<P>(以上程序在Apache+PHP4+mySQL和IIS+PHP4+mySQL中皆测试通过。)<BR></P> </td>
    </tr>
   <tr>
      <td align="RIGHT">(责任编辑:超越PHP)</td>
    </tr>
    </table>
    <table align="CENTER" width="85%" border="0" cellspacing="3" cellpadding="0">
    <tr>
      <td width="50%"><a href="/sendmail.php?aid=314" title="Send to Friend">[推荐给朋友]</a> <a href="/print.php?aid=314" title="Print" target="_blank">[显示打印版本]</a> </td>
      <td align="RIGHT" width="50%">更新日期:2003-01-19 浏览次数:<script language='Javascript' src='/view.php?aid=314'></script></td>
    </tr>
    </table>

   <script language="JavaScript" src="/note_show.php" type="text/javascript"></script>

    </td>
  <td valign="top" width="1" class="bg"><img src="/images/spacer.gif" alt="" width="1" height="1"></td>
  <td valign="top" width="20%" bgcolor="#DDDDDD" align="center">
  <br>
  <table align="CENTER" width="95%" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td bgcolor="#666666" class="cn1"> <img src="/images/arrow.gif" alt="" border=0> 相关文章</td>
    </tr>
    </table>
    <table align="CENTER" width="95%" border="0" cellspacing="3" cellpadding="0">
    <tr>
      <td> <ul><li><a href='/articles/372.shtml' title='用PHP函数解决SQL injection'>用PHP函数解决SQL injection</a></li>
<li><a href='/articles/353.shtml' title='用PHP实现验证码功能'>用PHP实现验证码功能</a></li>
<li><a href='/articles/348.shtml' title='用PHP工具包expat解析XML'>用PHP工具包expat解析XML</a></li>
<li><a href='/articles/333.shtml' title='使用phplib7.2中的Template处理BLOCK多重嵌套'>使用phplib7.2中的Template处理BLOCK多重嵌套</a></li>
<li><a href='/articles/312.shtml' title='使用PHP4中的 IntegratedTemplate类实现HTML和PHP代码分离'>使用PHP4中的 IntegratedTemplate类实现HTML和PHP代码分离</a></li>
<li><a href='/articles/311.shtml' title='使用PHP4中的 IntegratedTemplate类实现BLOCK功能'>使用PHP4中的 IntegratedTemplate类实现BLOCK功能</a></li>
<li><a href='/articles/310.shtml' title='用PHP4 和 PostgreSQL 构建一个电子商务应用'>用PHP4 和 PostgreSQL 构建一个电子商务应用</a></li>
<li><a href='/articles/220.shtml' title='用PHP制作静态网站的模板框架'>用PHP制作静态网站的模板框架</a></li>
<li><a href='/articles/218.shtml' title='用php实现文件上传二法'>用php实现文件上传二法</a></li>
<li><a href='/articles/212.shtml' title='用PHP发送MIME邮件(六)'>用PHP发送MIME邮件(六)</a></li>
</ul> </td>
    </tr>
    </table>
    </td>
   <td width="5" bgcolor="#BBBBBB"><img src="/images/spacer.gif" alt="" width="5" height="1"></td>
</tr>
</table>
<!-- MAIN TABLE END -->


<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
  <td><img src="/images/spacer.gif" width="1" height="1" alt=""></td>
   <td width="5" bgcolor="#333333"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>

<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#007770">
<tr>
  <td align="right">
   <a href="/?n=Source&file=article_show.php" title="查看源码"><span class="en2">view source</span></a> |
   <a href="/?n=FeedBack" title="留言反馈" target="_blank"><span class="en2">feedback</span></a> |
   <a href="javascript:void(0)" onclick="window.open('/site_send.php?n=www.phpe.net%2F%3Fn%3DReadArticle%26update%3D1%26a%3D314','','scrollbars=no,top=200,left=200,width=297,height=186')" title="发送链接"><span class="en2">send page</span></a> |
   <a href="/?n=SiteMap" title="站点地图"><span class="en2">sitemap</span></a> |
   <a href="/?n=Aboutus" title="关于我们"><span class="en2">aboutus</span></a>
   
   </td>
   <td width="5" bgcolor="#006C70"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>

<table width="765" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
  <td><img src="/images/spacer.gif" width="1" height="1" alt=""></td>
   <td width="5" bgcolor="#333333"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>

<table width="765" align="center" border="0" cellspacing="0" cellpadding="0" bgcolor="#BBBBBB">
<tr>
  <td align="right" height="40">
   <small>
   Copyright &copy; 2002-2004 PHPE TEAM. All rights reserved<br>
   Last updated:Mon Nov 1 15:55:03 2004 CST<br>
  Server sponsored by <a href="http://cncms.org"><small>cncms.org</small></a>
   </small>
  <br clear="all" />
  <img src="http://counter.china-channel.com/counter/count.exe?df=phpe.net&reload=T&dd=e&ft=0&trgb=ffffff">
  </td>
   <td width="10"> </td>
   <td width="5" bgcolor="#AAAAAA"><img src="/images/spacer.gif" width="5" height="1" alt=""></td>
</tr>
</table>

<script language="JavaScript" type="text/javascript" src="/js/pphlogger.js"></script>
<script language="JavaScript" type="text/javascript" src="/site_online.php?hide=1&file=article_show.php"></script>


</body>
</html>
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州维博网络(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:企业网站建设、网站程序开发、手机APP客户端、平面设计、主机域名、虚拟空间、网站推广、网站优化、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2024 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

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