gpt4 book ai didi

php - 正则表达式 - PHP

转载 作者:搜寻专家 更新时间:2023-10-31 20:43:27 25 4
gpt4 key购买 nike

我正在使用以下 PHP 代码

<?
$data = file_get_contents('http://www.kitco.com/texten/texten.html');
preg_match_all('/([A-Z]{3,5}\s+[0-9]{1,2},[0-9]{4}\s+([0-9.NA]{2,10}\s+){1,7})/si',$data,$result);

$records = array();
foreach($result[1] as $date) {
$temp = preg_split('/\s+/',$date);
$index = array_shift($temp);
$index.= array_shift($temp);
$records[$index] = implode(',',$temp);
}
print_R($records);
?>

读取以下数据

  --------------------------------------------------------------------------------
London Fix GOLD SILVER PLATINUM PALLADIUM
AM PM AM PM AM PM
--------------------------------------------------------------------------------
Jun 03,2013 1396.75 1402.50 22.4300 1466.00 1487.00 749.00 755.00
May 31,2013 1410.25 1394.50 22.5700 1471.00 1459.00 755.00 744.00
--------------------------------------------------------------------------------

我想做的是从下表中读取黄金(买价和卖价)价格,任何人都可以帮助更改正则表达式吗?

纽约现货价格 市场休市 将在

----------------------------------------------------------------------
Metals Bid Ask Change Low High
----------------------------------------------------------------------
Gold 1411.20 1412.20 +22.90 +1.65% 1390.10 1418.00
Silver 22.74 22.84 +0.48 +2.13% 22.26 23.08
Platinum 1495.00 1501.00 +41.00 +2.82% 1470.00 1511.00
Palladium 756.00 761.00 +7.00 +0.93% 750.00 766.00
----------------------------------------------------------------------
Last Update on Jun 03, 2013 at 17:14.58
----------------------------------------------------------------------

最佳答案

我不确定您是否可以修改现有的正则表达式以轻松匹配两个表,但如果您在字符串中有第二个表,则可以使用:

$string = "PLAIN TEXT TABLE DATA HERE";

preg_match('/Gold\s+(\d+\.\d{2})\s+(\d+\.\d{2})/',$string,$matches);

$goldBid = $matches[1];
$goldAsk = $matches[2];

关于php - 正则表达式 - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16910490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com