gpt4 book ai didi

php - 我想在网页上显示 .txt 文件中的文本行,并让它每天更新

转载 作者:行者123 更新时间:2023-11-28 15:21:09 25 4
gpt4 key购买 nike

我有一个 .txt 文件,其中包含包含日期的文本行(圣经经文)。我希望能够在我们的网站上显示文本,以便它显示当天的正确读数并每天更新。以下是文本示例:

Monday, December 28 — Psalm 148:1–6 Zechariah 10,11; Revelation 20:1–10

The Lord our God we will serve, and him we will obey. Joshua 24:24

Be steadfast, immovable, always excelling in the work of the Lord, because you know that in the Lord your labor is not in vain. 1 Corinthians 15:58

Tireless Creator, often we succumb to post-celebration doldrums. We lose our enthusiasm for service and witness. Help us remember that even in the dullness of daily routine we can share your grace. Rekindle the coals of our hearts with the fire of your love. Amen.

Tuesday, December 29 — Psalm 148:7–14 Zechariah 12–13:6; Revelation 20:11–21:8

God gives wisdom to the wise and knowledge to those who have understanding. Daniel 2:21

Do not be foolish, but understand what the will of the Lord is. Ephesians 5:17

It is difficult to discern your will, God of Wisdom. The Scriptures inform us, but interpretations can be controversial, even adversarial. Forgive our allowance of such disagreements to obstruct the work of your Spirit in us. Show us how to live the way, the truth, and the life of sacrificial love. Amen.

如果您能提供任何帮助,我们将不胜感激 - 我是一名代码爱好者,所以如果有帮助,最好将我视为新手。谢谢!

这是我一直在玩的那种 php 代码:

 <?php  // script.php


$searchfor = $_GET['january'];

$file = '2016 Daily Texts no hymns mac.txt';

$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/$pattern/m";

if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches:<br />";
echo implode("<br />", $matches[0]);
}
else{
echo "No matches found";
fclose ($file);
}
?>

最佳答案

只要日期格式在整个文本中始终保持一致

例如 12 月 28 日星期一

您的网页将能够毫无问题地每天提取一节新经文:

<?php

$today = date('l, F j');
$today_as_unix_timestamp = strtotime($today);
$tomorrow_as_unix_timestamp = ($today_as_unix_timestamp + (60 * 60 * 24));
$tomorrow = date('l, F j',$tomorrow_as_unix_timestamp);

$verses = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/2016_Daily_Texts_no_hymns_mac.txt');
$start = (strpos($verses,$today) + strlen($today));
$end = (strpos($verses,$tomorrow));

$verse_for_today = substr($verses,$start,($end - $start));

echo '<p>'.$verse_for_today.'</p>';

?>

关于php - 我想在网页上显示 .txt 文件中的文本行,并让它每天更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34683654/

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