Before in the company has written something similar, this time to help the previous boss wrote a simple acquisition program.
It's very simple. Sweat. There is no technical content.
Data Source: http://cn.finance.yahoo.co ...
Demo Address: Http://traffic02.100steps .....
(modified, added the data caching function.) Khan, did not use Lite_cache, himself wrote a simple kind of. )
Copy Code code as follows:
?
Set_time_limit (0);
$max _time=3600;
$cache _file= ' cache_yahoo.txt ';
$nowtime =time ();
if (!file_exists ($cache _file)) {
$filetime = 0;
}else{
$filetime =filemtime ($cache _file);
}
if ($filetime + $max _time< $nowtime) {
Update
Ob_start ();
function Get_yahoo_info ($url) {
$content =file_get_contents ($url);
$pattern = ' |<tr class= ' Yfnc_modtitle1 ' ><td><small><b> (. *) </b> \ ((. *) \) (. *) </ SMALL></TD><TD align= "right" >| U ';
Preg_match_all ($pattern, $content, $out);
$info [' company_name ']= $out [1][0];
$info [' Company_stock ']= $out [2][0];
$pattern = ' |<td class= "Yfnc_tablehead1" width= "52%" > Recent transaction Price: </TD><TD class= "Yfnc_tabledata1" >< Big><b> (. *) </b></big></td>| U ';
Preg_match_all ($pattern, $content, $out);
$info [' Stock_price ']= $out [1][0];
$pattern = ' |<td class= "Yfnc_tablehead1" width= "52%" > Ups and Downs: </td><td class= "Yfnc_tabledata1" > (. *) < /td>| U ';
Preg_match_all ($pattern, $content, $out);
$info [' Stock_upordown ']= $out [1][0];
$pattern = ' |<td class= "Yfnc_tablehead1" width= "54%" > Market value: </td><td class= "Yfnc_tabledata1" > (. *) < /td>| U ';
Preg_match_all ($pattern, $content, $out);
$info [' Stock_value ']= $out [1][0];
return $info;
}
$urls =explode (', ', file_get_contents (' url.txt '));
$i = 0;
$matchs =array ();
foreach ($urls as $url) {
$rs =get_yahoo_info ($url);
if (!empty ($rs)) {
$matchs [$i]= $rs;
$i + +;
$rs = ';
}
}
Print_r (Get_yahoo_info (' Http://cn.finance.yahoo.com/q?s=000063.SZ '));
?>
<table border= "1" width= "100%" cellpadding= "6" style= "Border-collapse:collapse" bordercolor= "#8CBFF9" cellspacing = "0" bgcolor= "#DFEDFD" >
<tr>
<TD width= "height=" "valign=" Top "bordercolor=" #ABD0FA "bgcolor=" #E1EEFD "> </td>
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#E1EEFD" ><div align= "center" > Company name </div></td >
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#E1EEFD" ><div align= "center" > Stock Code </DIV></TD >
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#E1EEFD" ><div align= "center" > Stock price </DIV></TD >
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#E1EEFD" ><div align= "center" > Stock gain </DIV></TD >
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#E1EEFD" ><div align= "Center" > Market Value </div></td>
</tr>
?
$i = 1;
foreach ($matchs as $match) {
?>
<tr>
<TD height= "" align= "center" valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#FFFFFF" ><?= $i?></td>
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#FFFFFF" ><div align= "center" ><?= $match [' Company_ Name ']?></div></td>
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#FFFFFF" ><div align= "center" ><?= $match [' Company_ Stock ']?></div></td>
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#FFFFFF" ><div align= "center" ><?= $match [' Stock_ Price ']?></div></td>
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#FFFFFF" ><div align= "center" ><?= $match [' Stock_ Upordown ']?></div></td>
<TD valign= "Top" bordercolor= "#ABD0FA" bgcolor= "#FFFFFF" ><div align= "center" ><?= $match [' Stock_ Value ']?></div></td>
</tr>
?
$i + +;
}?>
</table>
?
$content =ob_get_clean ();
$FP =fopen ($cache _file, ' W ');
if (! $fp) echo ' Open file failed ';
if (Flock ($FP, LOCK_EX)) {//Exclusive lock
if (!fwrite ($FP, $content)) echo ' File write Failed ';
Flock ($FP, lock_un); Release lock
} else {
echo "couldn ' t lock the file!";
if (!fwrite ($FP, $content)) echo ' File write Failed ';
}
Fclose ($FP);
Echo ' Cache time: '. Time ();
Echo $content;
}else{
Echo ' cache! ';
Echo file_get_contents ($cache _file);
}
?>