[PHP-users 30165] Re: 半角文字列、全文字置換したい。
Seiji Masugata
s.masugata @ digicom.dnp.co.jp
2006年 8月 28日 (月) 20:17:43 JST
こんにちわ、桝形です。
> 以下余談:
>
> 置き換えも str_replace でできると思うんですが、今試したらどうも
> バグってるくさい。
え?そうなのですか?
この結果、問題は無いと思ってますけど。。。
From: [26] => a
To: [26] => q
なので。
もしかして違う場所?だとしたらスミマセン。。。
From:
-------------------------------------------------
Array
(
[0] => A
[1] => B
[2] => C
[3] => D
[4] => E
[5] => F
[6] => G
[7] => H
[8] => I
[9] => J
[10] => K
[11] => L
[12] => M
[13] => N
[14] => O
[15] => P
[16] => Q
[17] => R
[18] => S
[19] => T
[20] => U
[21] => V
[22] => W
[23] => X
[24] => Y
[25] => Z
[26] => a
)
To:
-------------------------------------------------
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 7
[8] => 8
[9] => 9
[10] => a
[11] => b
[12] => c
[13] => d
[14] => e
[15] => f
[16] => g
[17] => h
[18] => i
[19] => j
[20] => k
[21] => l
[22] => m
[23] => n
[24] => o
[25] => p
[26] => q
[27] => r
[28] => s
[29] => t
[30] => u
[31] => v
[32] => w
[33] => x
[34] => y
[35] => z
[36] => A
[37] => B
[38] => C
[39] => D
[40] => E
[41] => F
[42] => G
[43] => H
[44] => I
[45] => J
[46] => K
[47] => L
[48] => M
[49] => N
[50] => O
[51] => P
[52] => Q
[53] => R
[54] => S
[55] => T
[56] => U
[57] => V
[58] => W
[59] => X
[60] => Y
[61] => Z
)
-------------------------------------------------
>
> $from = range('A', 'Z');
> $from[] = 'a';
>
> $to = array_merge(range('0', '9'), range('a', 'z'), range('A', 'Z'));
>
> $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
> $result = str_replace($from, $to, $str);
> var_dump($result);
--
Seiji Masugata <s.masugata @ digicom.dnp.co.jp>
PHP-users メーリングリストの案内