我需要帮助在PHP中解析以下CSV文件,因此我可以将内容插入到数据库中。
我知道我使用file_get_contents()
但在此之后我感到有些失落。
我想存储的内容。
我不确定将数据插入数据库表的最佳结构。
"**collection1**"
"events.href","**events.text**","**date**","index","url"
"tur.com/events/classic.html","John Deere Classic","Thursday Jul 9
- Sunday Jul 12, 2015","1","tur.com/r.html"
"collection2"
"**position**","name.href","**name.text**","**total**","index","url"
"--","javascript:void(0);","Scott","--","2","tur.com/r.html"
"--","javascript:void(0);","Billy","--","3","tur.com/r.html"
"--","javascript:void(0);","Jon","--","4","tur.com/r.html"
"--","javascript:void(0);","Bill","--","5","tur.com/r.html"
"--","javascript:void(0);","Tim","--","6","tur.com/r.html"
"--","javascript:void(0);","Carlos","--","7","tur.com/r.html"
"--","javascript:void(0);","Robert","--","8","tur.com/r.html"
"--","javascript:void(0);","Rod","--","9","tur.com/r.html"
答案 0 :(得分:0)
根据Java Regex - Tutorial ,我认为这需要细分为几个部分。目前看来它的范围太广了,无法回答。
file_get_contents()
阅读信息。通过将其回显到控制台,确保首先工作。 (从你的另一个问题来看,你认为如果URL没有.csv
后缀,这将无效。无论文件扩展名如何,它都应该有效 - 试试吧。如果失败,可能依赖于cookie或者JavaScript或其他一些问题)。INSERT
。我建议在这里使用PDO。确保绑定参数。如果您遇到特定的问题,可以提出一个新的焦点问题。目前,任务是将事情分解为离散的和可研究的部分。
值得记住的一个技巧是PHP手册的这个快捷方式。例如,如果您不知道fgetcsv
如何工作,请在浏览器地址栏中键入php.net/fgetcsv
,PHP站点将为您找到该功能。文档非常好。