Jump to content

Parse Months In cyrillic letters to numbers


Go to solution Solved by requinix,

Recommended Posts

Hello im trying to search this kind of parse. I have this string in variable:

$a = "май 2017";

How to parse to for example: "5 2017" or "5 17" or "5"

I can parse it from EN text but with cyrillic text i cant...

Please help

 

b.t.w i cant use array to store all cyrillic months because they coming from different script.

Edited by xfire123

 

This is my code:

 

if $filename = "Май 2017"

                    <?php
                        $dir_open = opendir('./WEBDams/Data/CHQ/HQ/1/');
                        while(false !== ($filename = readdir($dir_open))){
                                if($filename != "." && $filename != ".."){
                                    setlocale(LC_TIME, 'bg_BG.UTF-8','bulgarian');
                                    $filenameNOext = basename($filename, '.pdf');
                                    $filenameNOext2 = strftime($filenameNOext);
                                    $filenameNOext3 = preg_replace('/\d/', '', $filenameNOext2);
                                    $filenameNOext4 = preg_replace('/\s+/', '', $filenameNOext3);
                                    
                                    $link = "<li class='sort-item' data-event-date='$filenameNOext4'><a href='./WEBDams/Data/CHQ/HQ/1/$filename' ><strong> $filenameNOext г. $filenameNOext3</strong></a></li>";
                                    echo $link;
                                }
                        }
                        closedir($dir_open);

Im using it with this script:

    (function($){
    var container = $(".sort-list");
    var items = $(".sort-item");
    
    items.each(function() {
       // Convert the string in 'data-event-date' attribute to a more
       // standardized date format
       var BCDate = $(this).attr("data-event-date");
       var standardDate = BCDate[0];
       standardDate = new Date(standardDate).getTime();
       $(this).attr("data-event-date", standardDate);
 
    });
    

    items.sort(function(a,b){
        a = parseFloat($(a).attr("data-event-date"));
        b = parseFloat($(b).attr("data-event-date"));
        return a>b ? -1 : a<b ? 1 : 0;
    }).each(function(){
        container.prepend(this);
    });

})(jQuery);

/* This script sorts your list in descending order... to change it to ascending order change the "less than" operator (<) to "greater than" (>) */

But its not working for some reason... can you give me an example?

I can get it to work but only with a lowercase month name. Note that you're calling strptime() incorrectly.

 

How about IntlDateFormatter::parse (which will take me some time to get set up so I can't test it right now)?

I can get it to work but only with a lowercase month name. Note that you're calling strptime() incorrectly.

 

How about IntlDateFormatter::parse (which will take me some time to get set up so I can't test it right now)?

 

yes it can be with lowercase. I see the link but cant understand the method very well.

  • Solution

Try

$formatter = new IntlDateFormatter("bg_BG.UTF-8", null, null, null, null, "MMM yyyy");
$dt = $formatter->parse("Май 2017");
echo date("Y-m-d", $dt);
It does require you knowing what date format the filename uses, though.
  • Like 1

It giving me:

Fatal error: Uncaught Error: Class 'IntlDateFormatter' not found in C:\WEB\Apache24\htdocs\inc_req\menu_HQ.php:2 Stack trace: #0 C:\WEB\Apache24\htdocs\HQ.php(20): require() #1 {main} thrown in C:\WEB\Apache24\htdocs\inc_req\menu_HQ.php on line 2

I comment out extension=php_intl.dll restarted service. Still same error.

its say:

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\WEB\\PHP\\ext\\php_intl.dll' - The specified module could not be found.\r\n in Unknown on line 0

I fixed it when i copy all icu*.dll files in Apache bin directory... at last

 

I tested it and works like a charm. Thank you very much.

Edited by xfire123
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.