1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<?php
mb_language("Japanese");
mb_internal_encoding("UTF-8");
class Jen
{
function str_convert($name){
$name = $this->replace($name);
$str_array = $this->str_split($name);
foreach($str_array as $key => $value){
$ret_string .= $this->str_sort($value)." ";
}
return $ret_string;
}
/*
* 文字列の置き換え
*/
protected function replace($name){
$pattern = array(" ","\r\n","\n");
$st = str_replace ($pattern," ",$name);
return $st;
}
/*
* 文字列の並べ替え
*/
protected function str_sort($name){
$length = mb_strlen($name) - 1;
$flag = false;
if($length < 3){
return $name;
}
if(mb_substr($name,$length,1) == "。" || mb_substr($name,$length,1) == "、"){
$length--;
$flag = true;
}
$tmp = array();
for($i = 0; $i <= $length; $i++){
if($i == 0){
$tmp[$i] = mb_substr($name,0,1);
}else if($i == $length){
$tmp[$i] = mb_substr($name,$i,1);
}else{
$tmp[$i] = mb_substr($name,$length - $i,1);
}
}
if($flag){
$tmp[$length] .= mb_substr($name,$length + 1,1);
}
foreach($tmp as $key => $value){
$ret .= $value;
}
return $ret;
}
/*
* 文字列分解
*/
protected function str_split($name){
$r = mb_split(" ",$name);
return $r;
}
}
?>
|