Gooday Note Scrap Source Android login
 
작성일 : 10-06-23 14:44
[PHP] php
 글쓴이 : 관리자 (124.♡.25.159)
조회 : 3,964  
   http://www.virhac.com/board/bbs/?id=php&no=41&page=5 [617]
*** PHP *** [이 게시물은 관리자님에 의해 2011-03-28 13:36:20 scrap에서 이동 됨]

관리자 10-07-15 16:15
 124.♡.25.159  
round() 함수를 쓰면 실수를 정수로 반올림해준다 

만일 " round('실수', 2) "  이와 같은 형식으로 사용하게 되면 소수점 아래 둘째자리까지만 보여주게 되는데 이때 소수점 아래 세째자리에서 반올림이 일어난다

즉 반올림된 소수점 아래 둘째짜리까지를 보여준다
 

소수점 자릿수를 제한적으로 표시하고 싶으시다면 round() 함수를 쓰세여..

$a = 7; $b=3;

$c = $a / $b;

echo round($c,2);

결과 : 2.33

round() 함수의 뒷자리 파라미터는 자릿수를 표현 합니다.

위에는 2 이므로 소수점 둘째자리까지 표현하고 있습니다.

$a 와 $b, $c 는 php에서 변수 생성시에..숫자로 이루어져 있으면 자동으로 float 형 입니다.

님 같은경우 7/3 이 2만 출력된다 하셨는데 변수의 형태를 한번 살펴보시져..

만약 int 형으로 선언되었을 경우는 정수형 변수이므로 소숫점이 나오질 않습니다.

$a = (float)$a;    이렇게 실수형으로 형변환을 하셔야 소숫점이 나올것입니다
관리자 10-07-15 16:16
 124.♡.25.159  
*** 브라우저 정보 알아내기 ***

<?
$list = getBrowserType($_SERVER['HTTP_USER_AGENT']);

//echo $list['Name'].', '.$list['Version'];

$name = $list['Name'];
$version = $list['Version'];

echo "<script>var browserName = '$name'; var browserVersion = '$version';</script>";

function getBrowserType($log)
{
$log = strtolower($log);
$list    = array(
"Name"    =>    "unknown",
"Version"    =>    "0.0.0",                 
"Agent"    =>    "unknown"
);

$list['Agent']    = $log;

$browsers = array(
"firefox", "msie", "opera", "chrome", "safari",
"mozilla", "seamonkey",    "konqueror", "netscape",
"gecko", "navigator", "mosaic", "lynx", "amaya",
"omniweb", "avant", "camino", "flock", "aol"
);

foreach($browsers as $browser)
{
if (preg_match("#($browser)[/ ]?([0-9.]*)#", $log, $match))
{
$list['Name']        = $match[1] ;
$list['Version']    = $match[2] ;
break;
}
}

if($list['Name'] == "msie" && $list['Version'] == "6.0")
return $list;
}

function browserInfo() {

}
?>

<!--
<SCRIPT LANGUAGE="JavaScript">

function display() {
window.onerror=null;

colors = window.screen.colorDepth;
document.form.color.value = Math.pow (2, colors);

if (window.screen.fontSmoothingEnabled == true)
document.form.fonts.value = "Yes";
else document.form.fonts.value = "No";

document.form.navigator.value = navigator.appName;
document.form.version.value = navigator.appVersion;
document.form.colordepth.value = window.screen.colorDepth;
document.form.width.value = window.screen.width;
document.form.height.value = window.screen.height;
document.form.maxwidth.value = window.screen.availWidth;
document.form.maxheight.value = window.screen.availHeight;
document.form.codename.value = navigator.appCodeName;
document.form.platform.value = navigator.platform;

if (navigator.javaEnabled() < 1) document.form.java.value="No";
if (navigator.javaEnabled() == 1) document.form.java.value="Yes";

if(navigator.javaEnabled() && (navigator.appName != "Microsoft Internet Explorer")) {
vartool=java.awt.Toolkit.getDefaultToolkit();
addr=java.net.InetAddress.getLocalHost();
host=addr.getHostName();
ip=addr.getHostAddress();
alert("Your host name is '" + host + "'nYour IP address is " + ip);
}
}

</script>

<BODY OnLoad="display()">

<center>
<form name=form>
<table border=1 width=300>

<tr>
<td>current resolution:</td>
<td align=center><input type=text size=4 maxlength=4 name=width>
x <input type=text size=4 maxlength=4 name=height></td>
</tr>

<tr>
<td>
browser:</td>
<td align=center><input type=text size=20 maxlength=20 name=navigator></td>
</tr>
<tr>
<td>
max resolution:</td>
<td align=center><input type=text size=4 maxlength=4 name=maxwidth>
x <input type=text size=4 maxlength=4 name=maxheight></td>
</tr>

<tr>
<td>
version:</td>
<td align=center><input type=text size=20 maxlength=20 name=version></td>
</tr>

<tr>
<td>
color depth:</td>
<td align=center><input type=text size=2 maxlength=2 name=colordepth> bit</td>
</tr>

<tr>
<td>
code name:</td>
<td align=center><input type=text size=15 maxlength=15 name=codename></td>
</tr>

<tr>
<td>
platform:</td>
<td align=center><input type=text size=15 maxlength=15 name=platform></td>
</tr>

<tr>
<td>
colors:</td>
<td align=center><input type=text size=8 maxlength=8 name=color></td>
</tr>

<tr>
<td>
java enabled:</td>
<td align=center><input type=text size=3 maxlength=3 name=java></td>
</tr>

<tr>
<td>
anti-aliasing fonts:</td>
<td align=center><input type=text size=3 maxlength=3 name=fonts></td>
</tr>

<tr>
<td colspan=2 align=center>
<input type=button name=again value="again?" onclick="display()"></td>
</tr>
</table>
</form>
</center>

</body>
-->
관리자 10-08-03 21:14
 124.♡.25.159  
* 글자 길이 확인 (php)

 http://mwultong.blogspot.com/2007/04/php-cjk-string-length.html

  // strlen() 함수는, 문자열의 길이를 바이트 단위로 반환합니다.
  // 즉, 한글은 2바이트, 영문이나 기호는 1바이트로 출력
  print strlen("Cool") . "글자 (영문 바이트 단위)<br />\n";
  // 4글자 (영문 바이트 단위)


  // 공백이나 기호도 1글자
  print strlen("Cool Boy!") . "글자 (영문 바이트 단위)<br />\n";
  // 9글자 (영문 바이트 단위)


  // 한글 1자는 2글자로 간주
  print strlen("똠방각하") . "글자 (영문 바이트 단위)\n";
  // 8글자 (영문 바이트 단위)



  // 한글 글자수 정확히 구하기
  // 인코딩을 "EUC-KR" 로 지정하면 똠방각하 등에서 문제 발생.
  // 확장 완성형인 "CP949"를 지정해야 함
  print mb_strlen("똠방각", "CP949") . "글자 (한글 1자를 1자로 인식)<br />\n";
  // 3글자 (한글 1자를 1자로 인식)
관리자 10-08-09 14:57
 124.♡.25.159  
$file_name_only = substr($userfile_name,0,strrpos($userfile_name,"."));//파일이름
$file_name_ext = substr($userfile_name,strrpos($userfile_name,".")+1);//확장자이름
관리자 11-03-29 14:31
 124.♡.25.162  
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";
기리 11-04-11 18:28
 124.♡.25.162  
* 글자자르기
$contents1 = substr($post_content,0,5);

$contents1 = mb_substr($post_content,0,5,'utf-8');
기리 11-06-08 10:16
 123.♡.195.24  
* 글자 바꾸기 - strtr, str_replace

str_replace함수는 ASP의 Replace와 같은 역활을 하는데
사용법은
str_replace("찾을문자열","변경할문자열","문자열 원본")
예) $string ="This is a BIG test with SMALL RESULT";
echo str_replace("BIG","SMALL",$string);
결과값: This is a SMALL test with SMALL RESULT
 
원본 위치만다르고 쓰는 방식은 같다.
 
특이한 것은 strtr함수인데
이것은 1:1 바꿔주는 역활을 하는 함수이다.
사용법은
strtr("문자열","변경할문자열","변경할 문자열")
예)$string ="This is a BIG test with SMALL RESULT";
echo strtr($string,"BIG","SMALL");
결과값: This is a SMA test with SMALL RESULT
변경할 문자열의 length만큼 바뀌는 성실이 있다.
만약 다음 처럼 한다면
$string ="This is a big test with small result";
echo strtr($string,"big","small");
결과값:Thms ms a sma test wmth small result
보는 봐와 같이 b -> s, i -> m, g -> a로
치환이 되어 버린다. 이것을 str_replace처럼 쓰고 싶으면 배열을 이용해서 사용해도 된다.
 
 

Total 121
번호 제   목 글쓴이 날짜 조회
16 [PHP] 접속 정보 확인 기리 03-31 3168
15 [JavaScript] 날자계산 (1) 관리자 03-29 3028
14 [MySql] mysql - 외부접속 허용하기 기리 03-16 3654
13 [JavaScript] JavaScript (6) 기리 07-12 13490
12 [PHP] php (7) 관리자 06-23 3965
11 [MySql] Mysql 함수 기리 06-23 4131
10 [PHP] PHP xls, csv 출력 (1) 관리자 06-17 4586
9 [MySql] mysqldump (2) 기리 03-27 2331
8 [Linux] 리눅스 du (1) 관리자 03-23 2327
7 [Linux] crontab 관리 및 사용 관리자 03-08 2307
6 [PHP] PHP.INI 의 옵션 관리자 03-03 2505
5 Apache, MySQL, PHP 설치 가이드 (Linux) 관리자 03-03 1742
4 [PHP]SMTP에서 메일을 보내보자 관리자 03-03 2493
3 svn 변경된 파일만 export 하기 (1) 관리자 02-28 8631
2 [Linux] 리눅스 - 복사 강제 덮어쓰기 (3) 관리자 02-23 9529
 1  2  3  4  5  6  7  8  9