tomato兄,有些问题,
请问get_content之后,我们必须把拿到的内容换成其它格式才能搜索吗?从FTP里,也没有看到新的文件。。。
请问preg_match function里,如果我们要match nestle的股价的话,是不是要去match这个才能拿到股价?
- <span id="yfs_l10_4707.kl">
复制代码
"The Preg_Match PHP function is used to search a string, and return a 1 or 0. If the search was successful a 1 will be returned, and if it was not found a 0 will be returned"
*p/s:已经get到content和用echo证实了得到的content。但是得到的是整个网页的content。
alanlai12345 发表于 2010-10-29 11:11 PM
取得的當然是該網址的所有内容啊,所以接下来你要對 html 有些認知
看看一下你可以發現到你所要的資料都以放在 table 標簽中,那你就需要使用 preg_match_all 取出所有的 table 標簽。
如果根据正确的搜索条件并成功取得所有 table 之後,你就可以使用循环再對所有 table 做进一步的 preg_match 判断 table 中是否有其独特的某些关键字 (如:yfs_l10_4707.kl)
所以你已經會取得指定的網址内容後你所要了解的是
1. preg_match_all 和 preg_match 的 "Return Value" 与 "Parameters" 用法
2. preg_match & preg_match_all 的第一 parameter 所需的 Regular Expression 用法
第二點也許在你了解符号的意义之後就要多 google 一下其他不同網站的例子与說明才比較容易掌握,這點需要些時間和耐性。當然也可以搜索一下看看有没有现成的 RE 例子說明,也好方便你馬上套用。