首先,谢谢你阅读这篇文章!其次,我无法控制从其中获取数据的.txt文件。我希望能够获取数据并将其分割成完整的匹配,然后显示这些结果,然后显示即将到来的比赛,并显示这些结果。
例如:
最近完成的匹配
W6: John Smith vs. Joe Smith, 0-0
L7: Doug Smith vs. Jason Smith, 1-2
and so on即将到来的比赛
W1: Joan Smith vs. Bruce Smith, 0-0
W1: Jenn Smith vs. David Smith, 0-0
and so on这是一个示例文件:https://drive.google.com/file/d/11dW2pOK-MXHGRzQhJWb37tlWMqazj8UZ/view?usp=sharing
以上链接中的样本数据:
<|> Most Recent Completed Matches: W6: Jason Bertolo vs. Ed Gabele, 0-0 | W6: Ed Gabele vs. Jason Bertolo, 0-0 | L7: Doug Metcalf vs. Jason Bertolo, 1-2 | L6: Tom Walsh vs. Jason Bertolo, 0-2 | L5: Jason Bertolo vs. Kevin Kronk, 2-0 | L5: Tom Walsh vs. Zach Dotson, 2-0 | L4: Kevin Kronk vs. Bruce Patete, 2-1 | L4: Zach Dotson vs. Tom Dotson, 0-0 | L3: Bruce Patete vs. Joseph Hornback, 2-0 | L3: Kevin Kronk vs. Matt Smith, 2-1 | L3: Matt Borders vs. Tom Dotson, 1-2 | L3: Zach Dotson vs. Mick Pillar, 2-0 | L2: David Mosel vs. Joseph Hornback, 0-2 | L2: Antoine Tucker vs. Matt Smith, 0-0 | L2: Tom Dotson vs. Mike Conley, 2-1 | L2: Mick Pillar vs. Hannah Fields, 2-0 | L1: Mike Minor vs. Joseph Hornback, 0-2 | L1: David Mosel vs. Tom Johnson, 2-1 | L1: Matt Smith vs. Jennifer Hamilton, 2-1 | L1: Lori Fields vs. Mike Conley, 1-2 | L1: Owen Miller vs. Tom Dotson, 1-2 | L1: Ken Kronk vs. Hannah Fields, 0-2 | W5: Ed Gabele vs. Doug Metcalf, 3-1 | W4: Doug Metcalf vs. Tom Walsh, 3-2 | W4: Jason Bertolo vs. Ed Gabele, 1-3 | W3: Tom Walsh vs. Kevin Kronk, 3-0 | W3: Bruce Patete vs. Doug Metcalf, 1-3 | W3: Ed Gabele vs. Zach Dotson, 3-1 | W3: Matt Borders vs. Jason Bertolo, 0-3 | W2: Kevin Kronk vs. Ken Kronk, 3-2 | W2: Mick Pillar vs. Tom Walsh, 2-3 | W2: Doug Metcalf vs. Owen Miller, 3-2 | W2: Lori Fields vs. Bruce Patete, 1-3 | W2: Matt Smith vs. Zach Dotson, 1-3 | W2: Antoine Tucker vs. Ed Gabele, 0-3 | W2: David Mosel vs. Jason Bertolo, 0-3 | W2: Matt Borders vs. Mike Minor, 3-1 | W1: Joseph Hornback vs. Ken Kronk, 2-3 | W1: Tom Walsh vs. Tom Johnson, 3-0 | W1: Jennifer Hamilton vs. Bruce Patete, 0-3 | W1: Zach Dotson vs. Mike Conley, 3-2 | W1: Ed Gabele vs. Tom Dotson, 3-0 | W1: Mike Minor vs. Hannah Fields, 3-1 <|> Upcoming Matches: <|> 到目前为止,我尝试过的代码是:
<?php
$text = file_get_contents('https://drive.google.com/uc?export=download&id=11dW2pOK-MXHGRzQhJWb37tlWMqazj8UZ');
$json = (explode('|',$text));
//var_dump ($json);
//print "\n";
$trimmed = trim($text);
print_r ($trimmed);
?>它看起来很好,但对于我的生活,我不知道如何简单地列出两个字符之间的所有值。
有什么想法,我可以做什么来操纵这个文本,使我可以达到我想要的结果?
此外,您应该知道,该数据将在实际比赛期间每60秒更改一次。我不知道这是否重要,但我想我应该确保你知道这些数据不是静态的。唯一常量的东西是表示最近匹配或已完成匹配的<|>,并且结果总是在两个\\字符之间。
再次感谢您的时间!
发布于 2021-06-01 01:48:14
这是你需要的开始。有办法使它更紧凑,但我要澄清。您应该在preg_match调用的结果上添加错误检查,这样您就可以知道它是否因某种原因而失败。
<?php
$text = file_get_contents('sample_data');
// The sample data has two sections,
// one for completed matches and one for upcoming matches.
// Extract the 'variable' text of these two sections:
preg_match('/^ *<\|> Most Recent Completed Matches: (.+) <\|> Upcoming Matches: (.+) <\|> *$/', $text, $reg_matches);
$completed_text = $reg_matches[1];
$upcoming_text = $reg_matches[2];
// Within the text of a section, the matches are separated by '|',
// so split the section-text on that character:
$completed_array = explode("|", $completed_text);
$upcoming_array = explode("|", $upcoming_text);
echo "\n";
echo "Most Recent Completed Matches\n";
echo "\n";
foreach ( $completed_array as $match_text )
{
echo "$match_text\n";
}
echo "\n";
echo "Upcoming Matches\n";
echo "\n";
foreach ( $upcoming_array as $match_text )
{
echo "$match_text\n";
}
?>https://stackoverflow.com/questions/67771431
复制相似问题