Files
core/twe/func_string.php
T
Hide_D e536e2d4ca 내부 전역 변수값 처리를 위해 함수 정리
conf.php에 getServPrefix 추가. 이후 같은 db에서 다른 서버를 운용할때 사용 가능할 것으로 예상.

$_SESSION 값을 직접 받아서 처리하지 않도록 하기위한 용도로 getUserID(), getGeneralID(), getGeneralName() 을 설정

$_SESSION['p_id']를 p_no로 착각하여 구현한 부분 수정

int|null 변환을 위한 toInt 함수 추가

func_string.php에서 null이 입력될 경우 일부 처리

각 서버에 계정이 생성되었는지 확인하는 isSigned()함수 추가
2018-02-03 03:36:34 +09:00

332 lines
8.8 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
function getFont($str) {
if(strlen($str) >= 22) { $str = "<font size=1>{$str}</font>"; }
return $str;
}
function unfont($str) {
$str = str_replace("<font color=cyan>", "", $str);
$str = str_replace("<font color=limegreen>", "", $str);
$str = str_replace("<font color=magenta>", "", $str);
$str = str_replace("<font color=red>", "", $str);
$str = str_replace("</font>", "", $str);
return $str;
}
function SQ2DQ($str) {
return str_replace("'", "&#039;", $str);
}
function Tag2Code($str) {
// return htmlspecialchars(nl2br(str_replace(" ", "&nbsp;", $str)));
// $str = str_replace("&", "&amp;", $str);
$str = str_replace("'", "&#039;", $str);
$str = str_replace("\"", "&quot;", $str);
$str = str_replace("<", "&lt", $str);
$str = str_replace(">", "&gt", $str);
// $str = str_replace(" ", "&nbsp;", $str);
// return htmlspecialchars(nl2br($str));
return nl2br($str);
}
function BadTag2Code($str) {
/* FIXME: 제대로된 tag 변환 코드 사용 */
$str = str_replace("<script", "<sorry", $str);
$str = str_replace("<embed", "<sorry", $str);
return $str;
}
function tab($str, $maxsize, $ch) {
$size = strlen($str);
$string = '';
$count = ($maxsize - $size) / 2;
for($i=0; $i < $count; $i++) {
$string = "$string" . $ch;
}
$string = "$string" . "$str";
for($i=0; $i < $count; $i++) {
$string = "$string" . $ch;
}
return $string;
}
function tab2($str, $maxsize, $ch) {
$size = strlen($str);
$string = '';
$count = ($maxsize - $size);
for($i=0; $i < $count; $i++) {
$string = "$string" . $ch;
}
$string = "$string" . "$str";
return $string;
}
class _String {
public static function GetStrLen($str) {
$count = strlen($str);
$len = 0;
for($i=0; $i < $count; ) {
$code = ord($str[$i]);
if($code >= 0xf0) {
$len++;
$i += 4;
} elseif($code >= 0xe0) {
$len++;
$i += 3;
} elseif($code >= 0xc2) {
$len++;
$i += 2;
} else {
$len++;
$i += 1;
}
}
return $len;
}
public static function SubStr($str, $s, $l=1000) {
$count = strlen($str);
$startByte = 0; $isSet = 0;
$endByte = $count;
$len = 0;
for($i=0; $i < $count; ) {
$code = ord($str[$i]);
if($isSet == 0 && $len >= $s) {
$startByte = $i; $isSet = 1;
}
if($isSet == 1 && $len-$s >= $l) {
$endByte = $i;
break;
}
if($code >= 0xf0) {
$len++;
$i += 4;
} elseif($code >= 0xe0) {
$len++;
$i += 3;
} elseif($code >= 0xc2) {
$len++;
$i += 2;
} else {
$len++;
$i += 1;
}
}
$str = substr($str, $startByte, $endByte-$startByte);
return $str;
}
public static function SubStrForWidth($str, $s, $w) {
$count = strlen($str);
$startByte = 0; $isSet = 0;
$endByte = $count; $last = 0;
$len = 0;
$width = 0;
for($i=0; $i < $count; ) {
$code = ord($str[$i]);
if($isSet == 0 && $len >= $s) {
$startByte = $i; $isSet = 1;
$width = 0;
}
if($isSet == 1 && $width == $w) {
$endByte = $i;
break;
}
if($isSet == 1 && $width > $w) {
$endByte = $i - $last;
break;
}
if($code >= 0xf0) {
$len++;
$width += 2;
$last = 4;
$i += 4;
} elseif($code >= 0xe0) {
$len++;
$width += 2;
$last = 3;
$i += 3;
} elseif($code >= 0xc2) {
$len++;
$width += 2;
$last = 2;
$i += 2;
} else {
$len++;
$width += 1;
$last = 1;
$i += 1;
}
}
$str = substr($str, $startByte, $endByte-$startByte);
return $str;
}
public static function CutStrForWidth($str, $s, $w, $ch='..') {
$isCut = 0;
$count = strlen($str);
$startByte = 0; $isSet = 0;
$endByte = $count; $last = 0;
$len = 0;
$width = 0;
for($i=0; $i < $count; ) {
$code = ord($str[$i]);
if($isSet == 0 && $len >= $s) {
$startByte = $i; $isSet = 1;
$width = 0;
}
if($isSet == 1 && $width >= $w) {
$endByte = $i - $last;
$isCut = 1;
break;
}
if($code >= 0xf0) {
$len++;
$width += 2;
$last = 4;
$i += 4;
} elseif($code >= 0xe0) {
$len++;
$width += 2;
$last = 3;
$i += 3;
} elseif($code >= 0xc2) {
$len++;
$width += 2;
$last = 2;
$i += 2;
} else {
$len++;
$width += 1;
$last = 1;
$i += 1;
}
}
if($isCut != 0) {
$str = substr($str, $startByte, $endByte-$startByte) . $ch;
}
return $str;
}
//중간정렬
public static function staticFill($str, $maxsize, $ch) {
if(!$str){
$str = '';
}
$size = strlen($str);
$count = ($maxsize - $size) / 2;
for($i=0; $i < $count; $i++) {
$string = $string.$ch;
}
$string = $string.$str;
for($i=0; $i < $count; $i++) {
$string = $string.$ch;
}
return $string;
}
public static function Fill($str, $maxsize, $ch) {
if(!$str){
$str = '';
}
$size = strlen($str);
$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;
}
//우측정렬
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) {
$str = htmlspecialchars($str);
$str = str_replace("\r\n", "<br>", $str);
$str = str_replace("\n", "<br>", $str);
// return nl2br(htmlspecialchars($str));
// return htmlspecialchars($str);
return $str;
}
public static function NoSpecialCharacter($str) {
$str = str_replace(" ", "", $str);
$str = str_replace("\"", "", $str);
$str = str_replace("'", "", $str);
$str = str_replace("ⓝ", "", $str);
$str = str_replace("ⓜ", "", $str);
$str = str_replace("ⓖ", "", $str);
$str = str_replace("\\", "", $str);
$str = str_replace("/", "", $str);
$str = str_replace("`", "", $str);
$str = str_replace("-", "", $str);
$str = str_replace("=", "", $str);
$str = str_replace("[", "", $str);
$str = str_replace("]", "", $str);
$str = str_replace(";", "", $str);
$str = str_replace(",", "", $str);
$str = str_replace(".", "", $str);
$str = str_replace("~", "", $str);
$str = str_replace("!", "", $str);
$str = str_replace("@", "", $str);
$str = str_replace("#", "", $str);
$str = str_replace("$", "", $str);
$str = str_replace("%", "", $str);
$str = str_replace("^", "", $str);
$str = str_replace("&", "", $str);
$str = str_replace("*", "", $str);
$str = str_replace("(", "", $str);
$str = str_replace(")", "", $str);
$str = str_replace("_", "", $str);
$str = str_replace("+", "", $str);
$str = str_replace("|", "", $str);
$str = str_replace("{", "", $str);
$str = str_replace("}", "", $str);
$str = str_replace(":", "", $str);
$str = str_replace("", "", $str);
$str = str_replace("<", "", $str);
$str = str_replace(">", "", $str);
$str = str_replace("?", "", $str);
$str = str_replace(" ", "", $str);
return $str;
}
}