转换日期格式

发布于 2024-11-30 01:57:55 字数 1685 浏览 0 评论 0原文

我有一个脚本可以从另一个网站抓取/获取 html 表数据。网站日期格式是26/8/2011,如何将其更改为2011-12-13这种格式?

function createRSSFile($tag,$value,$data)
 {
    # this will return the each element with tag.
    $tag=strtolower(str_replace(" ","_",$tag));
    $tag=strtolower(str_replace(":","",$tag));
    $tag=strtolower(str_replace("&","and",$tag));
    $returnITEM = "<".$tag.">".htmlspecialchars(str_replace(" 00:00:00","",$value))."</".$tag.">";
    return $returnITEM;
 } 

    function fetchData($jobid) {
       $html=file_get_contents('http://acbar.org/JobDetail.aspx?id='.$jobid);
       $html=str_replace("<td></td>", "",$html);
      $html=str_replace("<td style=\"font-size:8pt;font-weight:bold;\"></td>","<td style=\"font-size:8pt;font-weight:bold;\">Null</td>",$html);
      $html=str_replace("<td style=\"font-size:8pt;font-weight:bold;\" colspan=\"2\" ></td>","<td style=\"font-size:8pt;font-weight:bold;\" colspan=\"2\" >Null</td>",$html);

       $html=str_replace("&nbsp;", " ",$html);
       $html=str_replace("?", "<br>",$html);
       $html=str_replace("<br>", "_br_",$html);

       $dom = new DOMDocument;
       $dom->loadHTML( $html );
       //echo $dom->saveHTML();
       //exit;
       $rows = array();
       foreach( $dom->getElementsByTagName( 'tr' ) as $tr ) {
        $cells = array();
        foreach( $tr->getElementsByTagName( 'td' ) as $td ) {
            if(trim($td->nodeValue)!='')
              $cells[] = str_replace("_br_","<br>",trim($td->nodeValue));
        }
         if(sizeof($cells)>0)
           $rows[] = $cells;
       }

I have script which scrap/fetch html table data from another website. The website date format is 26/8/2011, How I can change it to this format 2011-12-13??

function createRSSFile($tag,$value,$data)
 {
    # this will return the each element with tag.
    $tag=strtolower(str_replace(" ","_",$tag));
    $tag=strtolower(str_replace(":","",$tag));
    $tag=strtolower(str_replace("&","and",$tag));
    $returnITEM = "<".$tag.">".htmlspecialchars(str_replace(" 00:00:00","",$value))."</".$tag.">";
    return $returnITEM;
 } 

    function fetchData($jobid) {
       $html=file_get_contents('http://acbar.org/JobDetail.aspx?id='.$jobid);
       $html=str_replace("<td></td>", "",$html);
      $html=str_replace("<td style=\"font-size:8pt;font-weight:bold;\"></td>","<td style=\"font-size:8pt;font-weight:bold;\">Null</td>",$html);
      $html=str_replace("<td style=\"font-size:8pt;font-weight:bold;\" colspan=\"2\" ></td>","<td style=\"font-size:8pt;font-weight:bold;\" colspan=\"2\" >Null</td>",$html);

       $html=str_replace(" ", " ",$html);
       $html=str_replace("?", "<br>",$html);
       $html=str_replace("<br>", "_br_",$html);

       $dom = new DOMDocument;
       $dom->loadHTML( $html );
       //echo $dom->saveHTML();
       //exit;
       $rows = array();
       foreach( $dom->getElementsByTagName( 'tr' ) as $tr ) {
        $cells = array();
        foreach( $tr->getElementsByTagName( 'td' ) as $td ) {
            if(trim($td->nodeValue)!='')
              $cells[] = str_replace("_br_","<br>",trim($td->nodeValue));
        }
         if(sizeof($cells)>0)
           $rows[] = $cells;
       }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2024-12-07 01:57:55

总是可以对过去的日期进行计时,然后用日期格式化它,就像这样......

$timeToModify = strtotime($passedTime);
$formattedTime = date("Y-m-D", $timeToModify);

Could always strtotime the date passed, then format it however you wish with date, like so...

$timeToModify = strtotime($passedTime);
$formattedTime = date("Y-m-D", $timeToModify);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文