每天将Oscommerce和excel / csv文件自动导入我的数据库

时间:2012-07-14 11:19:41

标签: php excel text csv oscommerce

我想将文本文件转换为excel,然后修改excel文件中的某些数据,然后将这个新的excel文件导入数据库。

例如,excel文件的内容将是产品及其价格,修改将以价格为准。因此,数据库和网站上的产品更新将是自动的。我打算使用OSCommerce

我的问题是:是否有任何OSCommerce工具,我会为它配置它来完成这项工作,因为我需要每8小时自动执行一次这样的工作?我需要使用PHP从头开始编写脚本吗?

1 个答案:

答案 0 :(得分:0)

如果以简单的csv(逗号分隔值)格式保存excel文件,则可以使用逗号轻松分割它并使用PHP组织数据。

您可以使用以下代码从文件中读取数据:

$file_name = "test.csv"; // This needs to be relative to the current location that this script is being executed in 
$fp = fopen($file_name, "r"); // "r" means read, change to "rw" or "w" for read/write and write as needed
$data = fread($fp, filesize($file_name)); // Read the contents of the file into a string
fclose($fp); // Close the file for efficiency
$data = explode(',', $data); // Override data with the array format

这只是一个基本脚本,需要自己操作才能满足您的需求。上帝的运气:))

相关问题