我需要用PHP读取xml文件,但是xml文件有许多记录更新。我可以只读取10条记录的最近更新吗?
非常感谢。
在这种情况下,您应该编写自己的阅读器函数/类等。伪代码(可能有点像pythonic
):
stop_counter = 10 // 20, 30.... etc
file = open xml_file
put cursor in the begging of the file
xmlpart = ''
counter = 0
while (not end of file)
line = read single line from file
xmlpart += line
if (end of xml entry AND ++counter == stop_counter) // we can tell it by closed tag in line
break
然后解析xml的这一部分。非常容易的。