Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
楼主: alanlai12345
打印 上一主题 下一主题

【疑问】Dreamweaver - How to retrieve data from another website?

 关闭 [复制链接]

6

主题

0

好友

397

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

41#
发表于 2010-10-31 10:57 PM |只看该作者
回复 40# alanlai12345


    你测试就知道了


回复

使用道具 举报

2

主题

0

好友

39

积分

初级会员

Rank: 1

42#
发表于 2010-10-31 11:08 PM |只看该作者
本帖最后由 alanlai12345 于 2010-10-31 11:15 PM 编辑

回复 41# weeming21

对,我是试了才问的。

  1. <?php
  2. $homepage = file_get_contents("http://finance.yahoo.com/q/ta?s=4707.KL+Basic+Tech.+Analysis&t=3m") ;
  3.                 if ($homepage === false)
  4.                 (        echo "content not found";
  5.                         )
  6.                 else (
  7.                         preg_match_all ( "<span id=\"yfs_l10_4707.kl\">(.*)<\/span>", $homepage, $array)
  8.                         )
  9.                 print "Nestle: $array[1]";
  10. ?>
复制代码


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

43#
发表于 2010-10-31 11:33 PM |只看该作者
回复  weeming21

对,我是试了才问的。
alanlai12345 发表于 2010-10-31 11:08 PM



preg_match_all("/<span id=\"yfs_l10_4707.kl\">(.*)<\/span>/", $homepage, $array)


回复

使用道具 举报

6

主题

0

好友

397

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

44#
发表于 2010-10-31 11:38 PM |只看该作者
回复  weeming21

对,我是试了才问的。
alanlai12345 发表于 2010-10-31 11:08 PM


你和你自己38楼的代码作比较看看,怎么syntax不一样了?
if else 是用 { }, 不是用 ()
用pre_match就可以了,不需要用pre_match_all
"/<span..................span>/" 应该是要这样,不是  "<spa..............span>"
检查看看每句后面有没有输入;

建议搞清楚php基本语法


回复

使用道具 举报

2

主题

0

好友

39

积分

初级会员

Rank: 1

45#
发表于 2010-11-1 06:40 PM |只看该作者
本帖最后由 alanlai12345 于 2010-11-1 06:45 PM 编辑

终于preg match到了。。。
  1. <?php
  2. $homepage = file_get_contents("http://finance.yahoo.com/q/ta?s=4707.KL+Basic+Tech.+Analysis&t=3m") ;
  3.         if ($homepage === false)
  4.         {       echo "content not found";
  5.                 }
  6.         else {
  7.                 preg_match("/<span id=\"yfs_l10_4707.kl\">(.*)<\/span>/", $homepage, $array) ;
  8.                 print "Nestle: RM $array[1]";
  9.                 }
  10. ?>
复制代码


回复

使用道具 举报

6

主题

0

好友

397

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

46#
发表于 2010-11-1 06:45 PM |只看该作者
看清楚回复....
用pre_match就可以了,不需要用pre_match_all <======


回复

使用道具 举报

2

主题

0

好友

39

积分

初级会员

Rank: 1

47#
发表于 2010-11-1 08:59 PM |只看该作者
本帖最后由 alanlai12345 于 2010-11-2 11:42 PM 编辑

回复 46# weeming21
谢谢weeming21兄的指点

preg_match_all("/<span id=\"yfs_l10_4707.kl\">(.*)<\/span>/", $homepage, $array)

想在这里请问下,如何做到像tomato兄的演示例子?(除了share price,还有trade time,change。。。)
是用两个for loop和preg_match_all 来做吗?还是一只重复preg_match?

还有就是如果我们要把这些preg_match到的value放进table里的话。。。要如何做到呢?
  1. <table width="530" border="2">
  2.   <tr>
  3.     <th scope="col">STOCK CODE</th>
  4.     <th scope="col">NAME</th>
  5.     <th scope="col">REF</th>
  6.     <th scope="col">HIGH</th>
  7.     <th scope="col">LOW</th>
  8.     <th scope="col">LAST</th>
  9.     <th scope="col">CHANGE</th>
  10.     <th scope="col">VOLUME</th>
  11.   </tr>
  12.   <tr>
  13.     <td>4707</td>
  14.     <td>NESTLE</td>
  15.     <td>(this is example that i would like to put in the value into this section which i have preg_match earlier, is that possible?)</td>
  16.     <td>&nbsp;</td>
  17.     <td>&nbsp;</td>
  18.     <td>&nbsp;</td>
  19.     <td>&nbsp;</td>
  20.     <td>&nbsp;</td>
  21.   </tr>
  22. </table>
复制代码


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

48#
发表于 2010-11-3 02:55 AM |只看该作者
回复  weeming21
谢谢weeming21兄的指点


想在这里请问下,如何做到像tomato兄的?(除了s ...
alanlai12345 发表于 2010-11-1 08:59 PM


如果是 PHP 的话 请用 if  语句来判断 插入 <tr> <td> </td> </tr>


回复

使用道具 举报

6

主题

0

好友

397

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

49#
发表于 2010-11-3 04:53 AM |只看该作者
回复 47# alanlai12345

(this is example that i would like to put in the value into this section which i have preg_match earlier, is that possible?)

之前的print $array[1] 那里改成 $nestle = $array[1];
.........
然后你把这行
(this is example that i would like to put in the value into this section which i have preg_match earlier, is that possible?)
改成
<?=$nestle?>

就可以了


回复

使用道具 举报

2

主题

0

好友

39

积分

初级会员

Rank: 1

50#
发表于 2010-11-3 01:11 PM |只看该作者
(this is example that i would like to put in the value into this section which i have preg_match earlier, is that possible?)

之前的print $array[1] 那里改成 $nestle = $array[1];

谢谢weeming.
想在这里请问下,如何做到像tomato兄的演示例子?(除了share price,还有trade time,change。。。)
是用两个for loop和preg_match_all 来做吗?还是一只重复preg_match?

如果是 PHP 的话 请用 if  语句来判断 插入 <tr> <td> </td> </tr>

用if句来插入?怎么说呢?


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-29 02:34 AM , Processed in 0.092890 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部