source: branches/feature-module-paygent/data/downloads/module/mdl_paygent/jp/co/ks/merchanttool/connectmodule/util/StringUtil.php @ 15162

Revision 15162, 4.7 KB checked in by naka, 17 years ago (diff)

ペイジェント決済モジュール

Line 
1<?php
2/**
3 * PAYGENT B2B MODULE
4 * StringUtil.php
5 *
6 * Copyright (C) 2007 by PAYGENT Co., Ltd.
7 * All rights reserved.
8 * /
9
10/**
11 * Ú‘±ƒ‚ƒWƒ…[ƒ‹@StringUtitily
12 *
13 * @version $Revision: 1.6 $
14 * @author $Author: t-mori $
15 */
16
17class StringUtil{
18
19    /** ‹¤’Ê‚Å•ÏŠ·‚·‚éƒJƒ^ƒJƒi•¶Žš—ñ‚̃}ƒbƒsƒ“ƒOî•ñ‚ðŠi”[‚µ‚Ä‚¢‚éƒ}ƒbƒv */
20    var $katakanaMap = array();
21   
22    var $zenKana = array("ƒA", "ƒC", "ƒE", "ƒG", "ƒI", "ƒJ", "ƒL", "ƒN", "ƒP", "ƒR",
23            "ƒT", "ƒV", "ƒX", "ƒZ", /*"ƒ\", */"ƒ^", "ƒ`", "ƒc", "ƒe", "ƒg", "ƒi", "ƒj",
24            "ƒk", "ƒl", "ƒm", "ƒn", "ƒq", "ƒt", "ƒw", "ƒz", "ƒ}", "ƒ~", "ƒ€", "ƒ",
25            "ƒ‚", "ƒ„", "ƒ†", "ƒˆ", "ƒ‰", "ƒŠ", "ƒ‹", "ƒŒ", "ƒ", "ƒ", "ƒ’", "ƒ“",
26            "ƒK", "ƒM", "ƒO", "ƒQ", "ƒS", "ƒU", "ƒW", "ƒY", "ƒ[", "ƒ]", "ƒ_", "ƒa",
27            "ƒd", "ƒf", "ƒh", "ƒo", "ƒr", "ƒu", "ƒx", "ƒ{", "ƒ”", "ƒp", "ƒs", "ƒv",
28            "ƒy", "ƒ|", "ƒ@", "ƒB", "ƒD", "ƒF", "ƒH", "ƒƒ", "ƒ…", "ƒ‡", "ƒb", "[" );
29
30    var $hanKana = array("±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º",
31            "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ",
32            "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò",
33            "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "¦", "Ý",
34            "¶Þ", "·Þ", "¸Þ", "¹Þ", "ºÞ", "»Þ", "¼Þ", "½Þ", "¾Þ", "¿Þ",
35            "ÀÞ", "ÁÞ", "ÂÞ", "ÃÞ", "ÄÞ", "ÊÞ", "ËÞ", "ÌÞ", "ÍÞ", "ÎÞ",
36            "³Þ", "Êß", "Ëß", "Ìß", "Íß", "Îß", "§", "¨", "©", "ª", "«",
37            "¬", "­", "®", "¯", "°" );
38
39    /**
40     * ƒfƒtƒHƒ‹ƒgƒRƒ“ƒXƒgƒ‰ƒNƒ^
41     */
42    function StringUtil() {
43
44        if (count($this->zenKana) == count($this->katakanaMap)) {
45            return;
46        }
47       
48        for ($i = 0; $i < count($this->zenKana); $i++) {
49            $this->katakanaMap[$this->zenKana[$i]] = $this->hanKana[$i];
50        }
51    }
52   
53    /**
54     * ƒpƒ‰ƒ[ƒ^‚ª null ‚Ü‚½‚͋󕶎š‚©‚ð”»’f‚·‚é
55     *
56     * @param str String ”»’è‚·‚镶Žš—ñ
57     * @return <code>null</code>‚Ü‚½‚͋󕶎š‚̏ꍇA<code>true</code>
58     */
59    function isEmpty($str) {
60        return (!isset($str) || strlen(trim($str)) <= 0);
61    }
62
63    /**
64     * split(•ªŠ„”§ŒÀ”Å)
65     *
66     * @param str String •ªŠ„‘Ώە¶Žš—ñ
67     * @param delim String ‹æØ‚蕶Žš
68     * @param limit int Œ‹‰Ê‚Ì臒l
69     * @return String[] •ªŠ„Œã‚Ì•¶Žš”z—ñ
70     */
71    function split($str, $delim, $limit = -1) {
72       
73        $delimLength = strlen($delim);
74        $pos = 0;
75        $index = 0;
76        $list = array();
77        if ($delimLength != 0) {
78           
79            while (!(($index = strpos($str, $delim, $pos)) === false)) {
80                $list[] = substr($str, $pos, $index-$pos);
81                $pos = $index + $delimLength;
82                if ($pos >= strlen($str)) break;
83            }
84            if ($pos == strlen($str)) {
85                $list[] = "";       // the last is the delimiter.
86            } else  if ($pos < strlen($str)) {
87                $list[] = substr($str, $pos);
88            }
89        } else {
90            for ($i = 0; $i < strlen($str); $i++) {
91                $c = $str{$i};
92                $list[] = "" . $c;
93            }
94        }
95       
96        $rs = &$list;
97
98        if ((0 < $limit) && ($limit < count($rs))) {
99            // limit ‚æ‚èA•ªŠ„”‚ª‘½‚¢ê‡A•ªŠ„”‚ð limit ‚ɍ‡‚킹‚é
100            $temp = array();
101
102            $pos = 0;
103            for ($i = 0; $i < $limit - 1; $i++) {
104                $temp[] = $rs[$i];
105                $pos += strlen($rs[$i]) + strlen($delim);
106            }
107
108            $temp[$limit - 1] = substr($str, $pos);
109            for ($i = $limit; $i < count($rs); $i++) {
110                $sb = $temp[$limit - 1];       
111            }
112
113            $rs = $temp;
114        }
115
116        return $rs;
117    }
118
119    /**
120     * ”’l”»’è
121     *
122     * @param str String ”’l”»’è‘Ώە¶Žš—ñ
123     * @return boolean true=”’l false=”’lˆÈŠO
124     */
125    function isNumeric($str) {
126        $rb = is_numeric($str);
127
128        return $rb;
129    }
130
131    /**
132     * ”’lAŒ…””»’è
133     *
134     * @param str String ”’l”»’è‘Ώە¶Žš—ñ
135     * @param len int ”»’è‘ÎÛ Length
136     * @return boolean true=Œ…”“à”’l false=”’l‚Å‚È‚¢ or Œ…”ˆá‚¢
137     */
138    function isNumericLength($str, $len) {
139        $rb = false;
140
141        if (StringUtil::isNumeric($str)) {
142            if (strlen($str) == $len) {
143                $rb = true;
144            }
145        }
146
147        return $rb;
148    }
149
150    /**
151     * ‘SŠpƒJƒ^ƒJƒi•¶Žš‚𔼊pƒJƒ^ƒJƒi‚ÌŠY“–•¶Žš‚É•ÏŠ·‚·‚éB Žw’肳‚ꂽ•¶Žš—ñ‚ªnull‚̏ꍇ‚Ínull‚ð•Ô‚·B
152     *
153     * @param src String •ÏŠ·‚·‚錳‚Ì•¶Žš—ñ
154     * @return String •ÏŠ·Œã‚Ì•¶Žš—ñ
155     */
156    function convertKatakanaZenToHan($src) {
157        if ($src == null ) {
158            return null;
159        }
160        $str = mb_convert_kana($src, "kV", "SJIS");
161        return $str;
162    }
163
164    /**
165     * Žw’肳‚ꂽ•¶Žš—ñ‚ðŽw’肳‚ꂽƒ}ƒbƒsƒ“ƒOî•ñ‚ÉŠî‚« •ÏŠ·‚µ‚½Œ‹‰Ê‚Ì•¶Žš—ñ‚ð•Ô‚·B Žw’肳‚ꂽ•¶Žš—ñ‚ªnull‚̏ꍇ‚Ínull‚ð•Ô‚·B
166     *
167     * @param src String •ÏŠ·‚·‚錳‚Ì•¶Žš—ñ
168     * @param convertMap
169     *            Map •ÏŠ·‚̑ΏۂƂȂ镶Žš‚Æ•ÏŠ·Œã‚̃}ƒbƒsƒ“ƒOî•ñ‚ðŠi”[‚µ‚Ä‚¢‚éƒ}ƒbƒv
170     * @return String •ÏŠ·Œã‚Ì•¶Žš—ñ
171     */
172    function convert($src, $convertMap) {
173        if ($src == null) {
174            return null;
175        }
176        $chars = $this->toChars($src);
177        foreach ($chars as $c) {
178            if (array_key_exists($c, $convertMap)) {
179                $result .= $convertMap[$c];
180            } else {
181                $result .=$c;
182            }
183        }
184
185        return $result;
186    }
187
188    function toChars($str) {
189       
190        $chars = array();
191        for($i=0; $i<mb_strlen($str); $i++) {
192            $out = mb_substr($str, $i, 1);
193            $chars[] = $out;
194            $intx= 0;
195        }
196        return $chars;
197    }
198}
199    // ‰Šú‰»
200    $StringUtilInit = new StringUtil();
201    $StringUtilInit = null;
202?>
Note: See TracBrowser for help on using the repository browser.