PHP code example of ozawa / mecab_on_php

1. Go to this page and download the library: Download ozawa/mecab_on_php 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/ */

    

ozawa / mecab_on_php example snippets



use MecabOnPhp\mecab;

// mecabのパスを指定
$mecab_path = '/usr/local/bin/mecab';

// 解析対象の文章
$text = '富士には月見草がよく似合う';

// インスタンスを生成し、実行
$mecab = new Mecab($mecab_path);
$result = $mecab->execute($text);

var_dump($result);



// array(7) {
//   [0]=>
//   array(10) {
//     ["surface_form"]=>
//     string(6) "富士"
//     ["part_of_speech"]=>
//     string(6) "名詞"
//     ["subtype1"]=>
//     string(12) "固有名詞"
//     ["subtype2"]=>
//     string(6) "地域"
//     ["subtype3"]=>
//     string(6) "一般"
//     ["conjugational form"]=>
//     string(1) "*"
//     ["conjugational type"]=>
//     string(1) "*"
//     ["original"]=>
//     string(6) "富士"
//     ["katakana"]=>
//     string(6) "フジ"
//     ["pronounce"]=>
//     string(6) "フジ"
//   }
//   [1]=>
//   array(10) {
//     ["surface_form"]=>
//     string(3) "に"

.......