PHP code example of coooold / php_clc_parser

1. Go to this page and download the library: Download coooold/php_clc_parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

coooold / php_clc_parser example snippets


// 解析中图分类号,并获取对应的三级分类数组。注意,可能有多个结果,例如 
use \CLCParser\Parser;
Parser::parse('K825.2;E251-53');

/*
Array
(
    [K825.2] => Array
        (
            [0] => K
            [1] => K81
            [2] => K82
        )

    [E251-53] => Array
        (
            [0] => E
            [1] => E2
            [2] => E25
        )

)
*/

// 获取一二三级中图分类号对应的名称、路径信息
use \CLCParser\Parser;
Parser::getCLCInfoByCode('D92');

/*
Array
(
    [code] => D92
    [name] => 中国法律
    [path] => Array
        (
            [0] => D
            [1] => D9
            [2] => D92
        )

    [namePath] => Array
        (
            [0] => 政治、法律
            [1] => 法律
            [2] => 中国法律
        )

)
*/


$s = <<<DOC
        A
        O1-62
        J523.2"17"+3:G5
        TP312
        K837.125.6(202)+R173:G25a
        [X-019]
        F08:G40-054
        K876.3=49
        G49a
        K825.2;E251-53
        I287.8
        I712.45
        I611.65
        K854-53
        F0-0
        {D922.59} 
        DOC;

foreach (explode("\n", $s) as $code) {
    $code = trim($code);
    echo "\n===== 解析 ", $code, " ===== \n";

    $res = Parser::parse($code);
    foreach ($res as $k => $v) {
        echo "> $k :\n";
        $lastCode = array_pop($v);
        $info = Parser::getCLCInfoByCode($lastCode);
        print_r($info);
    }
}

composer