Home Backend Development PHP Tutorial 用PHP将数据导入到Foxmail_PHP

用PHP将数据导入到Foxmail_PHP

Jun 01, 2016 pm 12:32 PM
foxmail address import data document

最近小阳做了一个PHP同学录,同学们自己在那里添加或修改姓名、邮箱、OICQ等信息,并保存在mySQL数据库里。某日小阳突然想到,如果能用PHP生成一个文件,供同学们下载并把这些资料导入他们的Foxmail地址簿中,那该多好啊!
 
      说干就干,很快小阳便将这功能推出来了。那是如何实现的呢?这里仅以导出姓名、邮箱和OICQ三项予以说明。

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

点击查看原图

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

点击查看原图

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

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


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

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

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

点击查看原图

(以上程序在Apache+PHP4+mySQL和IIS+PHP4+mySQL中皆测试通过。)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

See all articles