【PHP】下らねぇ質問はID出して書き込みやがれ 124
■ このスレッドは過去ログ倉庫に格納されています
0633nobodyさん
2012/12/22(土) 22:33:05.11ID:b4fHgnvI$mecab = mecab_new();
$str_org = '私には夢があります。ベッカム夢の夢567 by 菊蔵下さいabcマートです。5本指。ABCマート。ABCマートベです。123';
$str=htmlspecialchars($_GET['comment'], ENT_QUOTES);
$noun_array = array();//名詞を格納する配列
$str2mecab=mb_convert_encoding ($str, "EUC-JP" , "UTF-8");
if ($node = mecab_sparse_tonode($mecab, $str2mecab)){
while ($node){
$node_array = mecab_node_toarray($node);
//char_typeが2、5、7の単語を抽出
if($node_array["char_type"] == "2" || $node_array["char_type"] == "5" || $node_array["char_type"] == "7"){
array_push($noun_array, $node_array["surface"]);
}
$node = mecab_node_next($node);
}}
$utf8_array=array();
foreach($noun_array as $value){
$value_utf8=mb_convert_encoding ($value, "UTF-8", "EUC-JP" );
array_push($utf8_array, $value_utf8);
}unset($value);
$str2php = implode("<br />\n",$utf8_array);
echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
$str2php<hr />
<form action="" method="get"><textarea name="comment" cols="50" rows="10">$str_org</textarea><br />
<input type="submit" value="Analysis" class="sbtn" /></form></body></html>
EOT;
mecab_destroy($mecab);
?>
■ このスレッドは過去ログ倉庫に格納されています