简体   繁体   English

如何使用html-simple-dom将月份名称转换为月份编号

[英]How to convert month name to month number using html-simple-dom

Hello someone can help me? 你好,有人可以帮我吗? to convert month name to month number. 将月份名称转换为月份编号。 Ok, let me explain. 好,让我解释一下。 I use CI framework, I make a web scraping, at the website have a date like this "21 NOVEMBER 2015" and I want to change the date/Posted_Date to be "2015-11-21" and store the date into my database. 我使用CI框架,进行网络抓取,在网站上有一个类似于“ 2015年11月21日”的日期,我想将date / Posted_Date更改为“ 2015-11-21”,并将该日期存储到我的数据库中。 I don't know why when I scrap the date, the date will be 1970-01-01. 我不知道为什么当我删除日期时,日期将是1970-01-01。 here I show my Controller function.Please 我在这里显示我的控制器功能。请

public function UMKDATA()
{
    $data = array();
    $this->load->library('simple_html_dom');
    $this->load->model('Vtender_Data');
    // create HTML DOM
    $html = file_get_html("http://www.umk.edu.my/index.php/en/component/k2/item/180-tender-dan-sebutharga");
    // get title
    $strA = $html->find('.itemFullText tbody tr');

    $j = 0;   
    foreach($strA as $strB)
    {
        if($j >= 1)
        {
            $strB->innertext;
            $strC = str_get_html($strB->innertext);
            $masuk['Title'] = str_get_html($strB->find('td',1)->innertext)->find('span',0)->innertext;
            if($this->Vtender_Data->check($masuk['Title']) == 0)
            {
                $masuk['source'] = $strC->find('td',0)->innertext;
                //$masuk['Opening_Date'] = ($strC->find('td',2)->innertext);
                //$masuk['Posted_Date'] = date("Y-m-d", strtotime($strC->find('td',3)->plaintext));


                $date = ($strC->find('td',3)->innertext) ;
                //$date = str_replace('', '', $date);
                $masuk['Posted_Date'] = date('Y-m-d', strtotime($date));


                //$masuk['Posted_Date'] = $strC->find('td',3)->plaintext;
                $masuk['Document'] = str_get_html($strC->find('td',4)->innertext)->find('a',0)->href;
                $masuk['URLNAME'] = 'UMK' ;
                $this->Vtender_Data->masuk($masuk);
            }
        }
        $j++;
    }

    $this->load->view('Admin/Home/header');
    $this->load->view('update_success');
    $this->load->view('footerLogin');

} 

Try below code . 尝试下面的代码。

It will take your date and convert it to unix timestamp first and the date() function will convert it into the result that you want. 它将花费您的日期,然后将其首先转换为unix时间戳,并且date()函数会将其转换为所需的结果。

strtotime — Parse about any English textual datetime description into a Unix timestamp strtotime —将任何英语文本日期时间描述解析为Unix时间戳

$date = "21 NOVEMBER 2015";
echo date('Y-m-d', strtotime($date));

Here is the doc if you want to explore more. 这里是文档,如果你想了解更多内容。 Hope it helps you . 希望对您有帮助。 Happy coding :) 快乐的编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM