2011-08-15 188 views
-2

我有脚本,从其他网站的废料/取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; 
     } 
+1

那不是仅仅是一个简单的正则表达式? –

回答

0

总是可以的strtotime通过的日期,然后格式化,但是你希望与日期,像这样......

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