Hello! Dear community, please tell me, maybe someone has already encountered this problem:

I get the line trace. view:

"Ноябрь 20 2012" "Декабрь 19 2012" "Сентябрь 12 2012" "Июнь 5 2012" "Август 2 2012" 

You must submit these lines in the next. format:

 11.20.2012 12.19.2012 09.12.2012 06.05.2012 08.02.2012 

Of course there is no problem to get the year and date, but what about the month?

I found a function that parses the date, but of course with the bummer month:

 $date = "Ноябрь 20 2012"; print_r(date_parse_from_format("F j Y", $date)); 

Help please advice how to be with the month!

IN ADDITION to the answer @ Indifferent :

 function newFormatDate($date) { $date = str_replace( array('Январь', 'Фервраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'), array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), $date); return date("dmY", strtotime($date)); } foreach($html->find('div.narrow_column div div.postdate') as $element) { $dateNews = $element->innertext; $date = $dateNews; $date = newFormatDate($dateNews); $array_dateNews[] = $date; } 
  • Something tells me that you need to manually check what month. - lampa
  • So here also suggests to me, but really ... :( - Artyomich

1 answer 1

I do not see anything difficult with conversion, the function is written in a minute. For example, this option:

 function newFormatDate($date) { $date = str_replace(array('Январь', 'Фервраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'), array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), $date); return date("dmY", strtotime($date)); } $date = 'Ноябрь 20 2012'; echo newFormatDate($date); /*Результат 20.11.2012 */ 
  • Thanks :) - Artyomich
  • @ Indifferent, please tell me , when executing the code (added a question), the result is 01/01/1970 - Artyomich
  • 1) the code does not work with dates before 1902 ... 2) I could incorrectly write the English name of the month ... 3) The date may come in the value 0. Give an example of an input date that the function cannot cope with. - Indifferent
  • 2
    ? what for? what do you need to change? save the file via notepad ++ in ANSI for win1251 or in UTF8 for UTF8, respectively. All bukaffki will be saved exactly in the selected encoding :) - thunder
  • one
    There is nothing to add to the @thunder comment ...) - Indifferent 4:39