StringUtil에 splitString, padString 추가
This commit is contained in:
+1
-1
@@ -85,7 +85,7 @@ $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""
|
|||||||
$histCount = MYDB_num_rows($result);
|
$histCount = MYDB_num_rows($result);
|
||||||
for($i=0; $i < $histCount; $i++) {
|
for($i=0; $i < $histCount; $i++) {
|
||||||
$history = MYDB_fetch_array($result);
|
$history = MYDB_fetch_array($result);
|
||||||
$value = "".$history['year'].StringUtil::Fill2($history['month'], 2, "0");
|
$value = "".$history['year'].StringUtil::padStringAlignRight($history['month'], 2, "0");
|
||||||
if($history['year'] == $year && $history['month'] == $month) {
|
if($history['year'] == $year && $history['month'] == $month) {
|
||||||
echo "
|
echo "
|
||||||
<option selected value={$value}>{$history['year']}년 {$history['month']}월</option>";
|
<option selected value={$value}>{$history['year']}년 {$history['month']}월</option>";
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ if($me['level'] == 0) {
|
|||||||
echo "
|
echo "
|
||||||
<option value={$city['city']}";
|
<option value={$city['city']}";
|
||||||
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
||||||
echo ">==================================================【".StringUtil::Fill($city['name'], 4, '_')."】";
|
echo ">==================================================【".StringUtil::padString($city['name'], 4, '_')."】";
|
||||||
if($city['nation'] == 0) echo "공백지";
|
if($city['nation'] == 0) echo "공백지";
|
||||||
elseif($me['nation'] == $city['nation']) echo "본국==";
|
elseif($me['nation'] == $city['nation']) echo "본국==";
|
||||||
else echo "타국==";
|
else echo "타국==";
|
||||||
@@ -69,7 +69,7 @@ if($me['level'] == 0) {
|
|||||||
echo "
|
echo "
|
||||||
<option value={$city['city']}";
|
<option value={$city['city']}";
|
||||||
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
||||||
echo ">==================================================【".StringUtil::Fill($city['name'], 4, '_')."】";
|
echo ">==================================================【".StringUtil::padString($city['name'], 4, '_')."】";
|
||||||
if($city['nation'] == 0) echo "공백지";
|
if($city['nation'] == 0) echo "공백지";
|
||||||
elseif($me['nation'] == $city['nation']) echo "본국==";
|
elseif($me['nation'] == $city['nation']) echo "본국==";
|
||||||
else echo "타국==";
|
else echo "타국==";
|
||||||
@@ -86,7 +86,7 @@ if($me['level'] == 0) {
|
|||||||
echo "
|
echo "
|
||||||
<option value={$city['city']}";
|
<option value={$city['city']}";
|
||||||
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
||||||
echo ">==================================================【".StringUtil::Fill($city['name'], 4, '_')."】";
|
echo ">==================================================【".StringUtil::padString($city['name'], 4, '_')."】";
|
||||||
if($city['nation'] == 0) echo "공백지";
|
if($city['nation'] == 0) echo "공백지";
|
||||||
elseif($me['nation'] == $city['nation']) echo "본국==";
|
elseif($me['nation'] == $city['nation']) echo "본국==";
|
||||||
else echo "타국==";
|
else echo "타국==";
|
||||||
@@ -112,7 +112,7 @@ if($myNation['level'] > 0) {
|
|||||||
echo "
|
echo "
|
||||||
<option value={$city['city']}";
|
<option value={$city['city']}";
|
||||||
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
|
||||||
echo ">==================================================【".StringUtil::Fill($city['name'], 4, '_')."】";
|
echo ">==================================================【".StringUtil::padString($city['name'], 4, '_')."】";
|
||||||
if($city['nation'] == 0) echo "공백지";
|
if($city['nation'] == 0) echo "공백지";
|
||||||
elseif($me['nation'] == $city['nation']) echo "본국==";
|
elseif($me['nation'] == $city['nation']) echo "본국==";
|
||||||
else echo "타국==";
|
else echo "타국==";
|
||||||
|
|||||||
+9
-3
@@ -1121,7 +1121,7 @@ function PushMsg($type, $nation, $picture, $imgsvr, $from, $fromcolor, $to, $toc
|
|||||||
else { $file = "_nation_msg{$nation}.txt"; }
|
else { $file = "_nation_msg{$nation}.txt"; }
|
||||||
$fp = fopen("logs/{$file}", "a");
|
$fp = fopen("logs/{$file}", "a");
|
||||||
//로그 파일에 기록
|
//로그 파일에 기록
|
||||||
$str = "{$type}|".StringUtil::Fill($from,12," ")."|".StringUtil::Fill($to,12," ")."|".$date."|".$msg."|".$fromcolor."|".$tocolor."|".$picture."|".$imgsvr;
|
$str = "{$type}|".StringUtil::padStringAlignRight($from,12," ")."|".StringUtil::padStringAlignRight($to,12," ")."|".$date."|".$msg."|".$fromcolor."|".$tocolor."|".$picture."|".$imgsvr;
|
||||||
fwrite($fp, "{$str}\n");
|
fwrite($fp, "{$str}\n");
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
@@ -1342,9 +1342,15 @@ function updateTraffic() {
|
|||||||
$db->update('general', ['refresh'=>0], true);
|
$db->update('general', ['refresh'=>0], true);
|
||||||
|
|
||||||
$date = date('Y-m-d H:i:s');
|
$date = date('Y-m-d H:i:s');
|
||||||
$fp = fopen("logs/_traffic.txt", "a");
|
|
||||||
//일시|년|월|총갱신|접속자|최다갱신자
|
//일시|년|월|총갱신|접속자|최다갱신자
|
||||||
$msg = StringUtil::Fill2($date,20," ")."|".StringUtil::Fill2($game['year'],3," ")."|".StringUtil::Fill2($game['month'],2," ")."|".StringUtil::Fill2($game['refresh'],8," ")."|".StringUtil::Fill2($online,5," ")."|".StringUtil::Fill2($user['name']."(".$user['refresh'].")",20," ");
|
file_put_contents(__dir__."logs/_traffic.txt",
|
||||||
|
StringUtil::padStringAlignRight($date,20," ")
|
||||||
|
."|".StringUtil::padStringAlignRight($game['year'],3," ")
|
||||||
|
."|".StringUtil::padStringAlignRight($game['month'],2," ")
|
||||||
|
."|".StringUtil::padStringAlignRight($game['refresh'],8," ")
|
||||||
|
."|".StringUtil::padStringAlignRight($online,5," ")
|
||||||
|
."|".StringUtil::padStringAlignRight($user['name']."(".$user['refresh'].")",20," ")
|
||||||
|
, FILE_APPEND);
|
||||||
fwrite($fp, $msg."\n");
|
fwrite($fp, $msg."\n");
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -740,10 +740,10 @@ function command_Other($turn, $commandtype) {
|
|||||||
|
|
||||||
|
|
||||||
function EncodeCommand($fourth, $third, $double, $command) {
|
function EncodeCommand($fourth, $third, $double, $command) {
|
||||||
$str = StringUtil::Fill2($fourth, 4, "0");
|
$str = StringUtil::padStringAlignRight($fourth, 4, "0");
|
||||||
$str .= StringUtil::Fill2($third, 4, "0");
|
$str .= StringUtil::padStringAlignRight($third, 4, "0");
|
||||||
$str .= StringUtil::Fill2($double, 4, "0");
|
$str .= StringUtil::padStringAlignRight($double, 4, "0");
|
||||||
$str .= StringUtil::Fill2($command, 2, "0");
|
$str .= StringUtil::padStringAlignRight($command, 2, "0");
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,9 @@ function processGoldIncome() {
|
|||||||
// 실지급율
|
// 실지급율
|
||||||
$ratio = $realoutcome / $originoutcome;
|
$ratio = $realoutcome / $originoutcome;
|
||||||
}
|
}
|
||||||
$adminLog[] = StringUtil::Fill2((string)$nation['name'],12," ")
|
$adminLog[] = StringUtil::padStringAlignRight((string)$nation['name'],12," ")
|
||||||
." // 세금 : ".StringUtil::Fill2((string)$income,6," ")
|
." // 세금 : ".StringUtil::padStringAlignRight((string)$income,6," ")
|
||||||
." // 세출 : ".StringUtil::Fill2((string)$originoutcome,6," ")
|
." // 세출 : ".StringUtil::padStringAlignRight((string)$originoutcome,6," ")
|
||||||
." // 실제 : ".tab2((string)$realoutcome,6," ")
|
." // 실제 : ".tab2((string)$realoutcome,6," ")
|
||||||
." // 지급율 : ".tab2((string)round($ratio*100,2),5," ")
|
." // 지급율 : ".tab2((string)round($ratio*100,2),5," ")
|
||||||
." % // 결과금 : ".tab2((string)$nation['gold'],6," ");
|
." % // 결과금 : ".tab2((string)$nation['gold'],6," ");
|
||||||
@@ -408,9 +408,9 @@ function processRiceIncome() {
|
|||||||
// 실지급율
|
// 실지급율
|
||||||
$ratio = $realoutcome / $originoutcome;
|
$ratio = $realoutcome / $originoutcome;
|
||||||
}
|
}
|
||||||
$adminLog[] = StringUtil::Fill2($nation['name'],12," ")
|
$adminLog[] = StringUtil::padStringAlignRight($nation['name'],12," ")
|
||||||
." // 세곡 : ".StringUtil::Fill2((string)$income,6," ")
|
." // 세곡 : ".StringUtil::padStringAlignRight((string)$income,6," ")
|
||||||
." // 세출 : ".StringUtil::Fill2((string)$originoutcome,6," ")
|
." // 세출 : ".StringUtil::padStringAlignRight((string)$originoutcome,6," ")
|
||||||
." // 실제 : ".tab2((string)$realoutcome,6," ")
|
." // 실제 : ".tab2((string)$realoutcome,6," ")
|
||||||
." // 지급율 : ".tab2((string)round($ratio*100,2),5," ")
|
." // 지급율 : ".tab2((string)round($ratio*100,2),5," ")
|
||||||
." % // 결과곡 : ".tab2((string)$nation['rice'],6," ");
|
." % // 결과곡 : ".tab2((string)$nation['rice'],6," ");
|
||||||
|
|||||||
@@ -939,7 +939,13 @@ function fight($tnmt_type, $tnmt, $phs, $group, $g1, $g2, $type) {
|
|||||||
$energy1 = round($energy1); $energy2 = round($energy2);
|
$energy1 = round($energy1); $energy2 = round($energy2);
|
||||||
$damage1 = round($damage1); $damage2 = round($damage2);
|
$damage1 = round($damage1); $damage2 = round($damage2);
|
||||||
|
|
||||||
$log[] = "<S>●</> ".StringUtil::Fill2($phase, 2, "0")."合 : <C>".StringUtil::Fill2($energy1, 3, "0")."</> <span class='ev_highlight'>(-".StringUtil::Fill2($damage1, 3, "0").")</span> vs <span class='ev_highlight'>(-".StringUtil::Fill2($damage2, 3, "0").")</span> <C>".StringUtil::Fill2($energy2, 3, "0")."</>";
|
$log[] = '<S>●</> '
|
||||||
|
.StringUtil::padStringAlignRight($phase, 2, "0").'合 : '
|
||||||
|
.'<C>'.StringUtil::padStringAlignRight($energy1, 3, "0").'</>'
|
||||||
|
.'<span class="ev_highlight">(-'.StringUtil::padStringAlignRight($damage1, 3, "0").')</span>'
|
||||||
|
.' vs '
|
||||||
|
.'<span class="ev_highlight">(-'.StringUtil::padStringAlignRight($damage2, 3, "0").')</span>'
|
||||||
|
.'<C>'.StringUtil::padStringAlignRight($energy2, 3, "0").'</>';
|
||||||
|
|
||||||
if($energy1 <= 0 && $energy2 <= 0) {
|
if($energy1 <= 0 && $energy2 <= 0) {
|
||||||
if($type == 0) { $sel = 2; break; }
|
if($type == 0) { $sel = 2; break; }
|
||||||
|
|||||||
+61
-37
@@ -168,27 +168,69 @@ class StringUtil
|
|||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
//중간정렬
|
function splitString($str, $l = 0) {
|
||||||
public static function staticFill($str, $maxsize, $ch)
|
//https://php.net/manual/kr/function.str-split.php#107658
|
||||||
{
|
if ($l > 0) {
|
||||||
if (!$str) {
|
$ret = array();
|
||||||
$str = '';
|
$len = mb_strlen($str, "UTF-8");
|
||||||
|
for ($i = 0; $i < $len; $i += $l) {
|
||||||
|
$ret[] = mb_substr($str, $i, $l, "UTF-8");
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
$size = strlen($str);
|
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
$count = ($maxsize - $size) / 2;
|
|
||||||
$string = '';
|
|
||||||
|
|
||||||
for ($i=0; $i < $count; $i++) {
|
|
||||||
$string = $string.$ch;
|
|
||||||
}
|
|
||||||
$string = $string.$str;
|
|
||||||
for ($i=0; $i < $count; $i++) {
|
|
||||||
$string = $string.$ch;
|
|
||||||
}
|
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* str_pad를 유니코드에서 사용할 수 있는 함수, monospace 전각, 반각 구분을 포함.
|
||||||
|
* @param string $str 원본 문자열
|
||||||
|
* @param int $maxsize 채우고자 하는 너비. 전각 문자는 2, 반각 문자는 1을 기준으로 함
|
||||||
|
* @param string $ch 채움 문자열
|
||||||
|
* @param int $position 원본 문자열의 위치. -1:왼쪽(오른쪽을 채움), 0:가운데(양쪽을 채움), 1:오른쪽(왼쪽을 채움)
|
||||||
|
* @return string 채워진 문자열. 완벽히 채울 수 없는 경우 $maxsize보다 살짝 작은 길이로 반환 됨.
|
||||||
|
*/
|
||||||
|
public static function padString(string $str, int $maxsize, string $ch = ' ', int $position = 0){
|
||||||
|
$chLen = mb_strwidth($ch, 'UTF-8');
|
||||||
|
|
||||||
|
if($chLen == 0){
|
||||||
|
return padString($str, $maxsize, ' ', $position);
|
||||||
|
}
|
||||||
|
|
||||||
|
$textLen = mb_strwidth($str, 'UTF-8');
|
||||||
|
|
||||||
|
$fillTextCnt = intdiv($maxsize - $textLen, $chLen);
|
||||||
|
|
||||||
|
if($position < 0){
|
||||||
|
$fillLeftCnt = 0;
|
||||||
|
$fillRightCnt = $fillTextCnt;
|
||||||
|
}
|
||||||
|
else if($position > 0){
|
||||||
|
$fillLeftCnt = $fillTextCnt;
|
||||||
|
$fillRightCnt = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$fillLeftCnt = intdiv($fillTextCnt, 2);
|
||||||
|
$fillRightCnt = $fillTextCnt - $fillLeftCnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str_repeat($ch, $fillLeftCnt).$str.str_repeat($ch, $fillRightCnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function padStringAlignRight(string $str, int $maxsize, string $ch = ' '){
|
||||||
|
return static::padString($str, $maxsize, $ch, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function padStringAlignLeft(string $str, int $maxsize, string $ch = ' '){
|
||||||
|
return static::padString($str, $maxsize, $ch, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function padStringAlignCenter(string $str, int $maxsize, string $ch = ' '){
|
||||||
|
return static::padString($str, $maxsize, $ch, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
public static function Fill($str, $maxsize, $ch)
|
public static function Fill($str, $maxsize, $ch)
|
||||||
{
|
{
|
||||||
if (!$str) {
|
if (!$str) {
|
||||||
@@ -209,24 +251,6 @@ class StringUtil
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
//우측정렬
|
|
||||||
public static function Fill2($str, $maxsize, $ch='0')
|
|
||||||
{
|
|
||||||
if (!$str) {
|
|
||||||
$str = '';
|
|
||||||
}
|
|
||||||
$size = strlen($str);
|
|
||||||
|
|
||||||
$count = ($maxsize - $size);
|
|
||||||
$string = '';
|
|
||||||
for ($i=0; $i < $count; $i++) {
|
|
||||||
$string = $string.$ch;
|
|
||||||
}
|
|
||||||
$string = $string.$str;
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function EscapeTag($str)
|
public static function EscapeTag($str)
|
||||||
{
|
{
|
||||||
$str = htmlspecialchars($str);
|
$str = htmlspecialchars($str);
|
||||||
|
|||||||
Reference in New Issue
Block a user