在特定日期或时间自动从html源代码中删除特定代码?

问题描述 投票:0回答:1

[我想在特定日期或时间从我的HTML源代码中删除一些代码,例如,如果我想在2019年10月25日删除一些代码,因此该日期之后应从源代码中删除。

例如:

<!DOCTYPE html>
<html>
<head>
  <title>Demo Html code</title>
</head>
<body>
<p>some demo parragraph content</p>

<!-- This code should be removed after 25-10-2019-->
<script type="application/ld+json"> { "@context" : "http://schema.org/", "@type" : "JobPosting" }
    </script>
<!-- code end here -->
</body>
</html>
javascript jquery html dom
1个回答
0
投票

动态删除源代码(虽然可以以非常慢的速度执行)不是很实际,我要做的是创建一个工作发布表(或者经过一段时间后要隐藏的其他任何内容)在数据库中,并且仅从数据库中检索仍处于活动状态的行。这可以通过评估日期或手动为active列设置布尔值。

public static function getActiveJobPostings() {
    $conn = new PDO( db_host, db_user, db_pw );
    $sql = "SELECT * FROM jobpostings WHERE active = true ORDER BY closingdate ASC";

    $st = $conn->prepare( $sql );
    $st->execute();
    $list = array();

    while ( $row = $st->fetch() ) {
      $job = new JobPosting( $row );
      $list[] = $job;
    }

    $sql = "SELECT FOUND_ROWS() AS totalRows";
    $totalRows = $conn->query( $sql )->fetch();
    $conn = null;
    return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
}

$postings = JobPosting::getActiveJobPostings();
foreach($postings['results'] as $ad) {
echo '<script type="application/ld+json"> { "@context" : "http://schema.org/", "@type" : "JobPosting" }
</script>'
}

为此,您首先需要创建一个伴随类,该类将表的列值存储为类变量,以便为每个选定的行都有一个对象。

© www.soinside.com 2019 - 2024. All rights reserved.