메뉴 건너뛰기

프로그램언어

조회 수 25432 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

랜덤하게 1~45까지 숫자를 빼오는데 중복되지 않게 숫자 6개를 빼서
Array 로 return 합니다.


<? 
function getLotto() { 
$i=0; 
while(count($tmp)<6) { 
srand ((double) microtime() * 1000000); 
$tmp[$i] = mt_rand(1,45); 
$tmp = array_unique($tmp); 
if (count($tmp)==$i+1) { 
$i++; 
} 
} 
sort($tmp); 
return $tmp; 
} 
?> 


소스 전문


<? 
/*************************************** 
# Source Name : lotto.php 
# Information : Lotto 6/45 .. 숫자 
# Programer Wizard (http://wizard.ncafe.net wizard@ncafe.net) 
# History : - 
***************************************/ 
function getLotto() { 
$i=0; 
while(count($tmp)<6) { 
srand ((double) microtime() * 1000000); 
$tmp[$i] = mt_rand(1,45); 
$tmp = array_unique($tmp); 
if (count($tmp)==$i+1) { 
$i++; 
} 
} 
sort($tmp); 
return $tmp; 
} 

function getTable() { 
$rehtml = "<table border=0 cellspacing=1 cellpadding=2>rn"; 
$rehtml .= "t<tr>rn"; 
$rehtml .= "tt<td colspan=7 height=1 bgcolor=green></td>rn"; 
$rehtml .= "t</tr>rn"; 
$rehtml .= "t<tr align=center>rn"; 
$rehtml .= "tt<td width=40 nowrap>게임</td>rn"; 
for ($i=1;$i<=6;$i++) { 
$rehtml .= "tt<td width=20 nowrap>".$i."</td>rn"; 
} 
$rehtml .= "t<tr>rn"; 
$rehtml .= "tt<td colspan=7 height=1 bgcolor=green></td>rn"; 
$rehtml .= "t</tr>rn"; 
$game = array("A","B","C","D","E"); 
$j=0; 
while($j<5) { 

$lotto = getLotto(); 
if (count($lotto)!=6) { 
$rehtml .= "===error - 이번주엔 로또 사지마세요."; 
exit; 
} 
$rehtml .= "t<tr align=center>rn"; 
$rehtml .= "tt<td nowrap>".$game[$j]."</td>rn"; 
for ($i=0;$i<count($lotto);$i++) { 
$rehtml .= "tt<td nowrap>".$lotto[$i]."</td>rn"; 
} 
$rehtml .= "</tr>rn"; 
$rehtml .= "t<tr>rn"; 
$rehtml .= "tt<td colspan=7 height=1 bgcolor=green></td>rn"; 
$rehtml .= "t</tr>rn"; 
$j++; 
} 
$rehtml .= "</table>rn"; 

return $rehtml; 
} 

if (!$loop) { $loop=1; } 

$cut=5; 
$bgcolor="black"; 

// $save 는 원래 엑셀로 저장하기 위해서 만든 부분인데.. 저장은 됩니다만 
// 화면에서 보여진거와 다르게 저장됩니다. 귀찮아서. 여기까지만... 
if ($save) { 
$cut=3; 
$bgcolor="white"; 
header("Content-type: application/vnd.ms-excel"); 
header("Content-Disposition: attachment; filename=Lotto.xls" ); 
header("Content-Description: PHP4 Generated Data"); 
} 
$create = "<a href="http://wizard.ncafe.net/bbs.php?board=linux&mode=view&bbsno=28&start=0&que=&queMod=" target=_blank>소스보기</a> create By <a href=http://wizard.ncafe.net/><b>Wizard</b></a>"; 
$html = "<html>rn"; 
$html .= "<title>꿈의 Lotto</title>rn"; 
$html .= "<head>rn"; 
if (!$save) { 
$html .= "<link rel=stylesheet href=http://ncafe.org/wizard.css type=text/css>rn"; 
$html .= "<script language=javascript>rn"; 
$html .= "function change() {rn"; 
$html .= " location.href='".$PHP_SELF."?loop='+document.main.loop.value; rn"; 
$html .= "}rn"; 
$html .= "</script>rn"; 
} 
$html .= "</head>rn"; 
$html .= "<body bgcolor=".$bgcolor.">rn"; 
$html .= "<form name=main>rn"; 
$html .= "<select name=loop class=ise onchange=change()>rn"; 
for ($i=1;$i<=20;$i++) { 
if ($i==$loop) { 
$html .= "t<option value=".$i." selected>".$i."장</option>rn"; 
} else { 
$html .= "t<option value=".$i.">".$i."장</option>rn"; 
} 
} 
$html .= "</select>rn"; 
$html .= " 대박나세요~!!!!!!!!!!rn"; 
$html .= "</form>rn"; 
$html .= "<table border=0 cellspacing=1 cellpadding=2>rn"; 
$i=0; 
while ($i<$loop) { 
if (!$i%$cut) { $html .= "t<tr>rn"; } 
$html .= "tt<td>"; 
$html .= getTable(); 
$html .= "</td>rn"; 

if ($save) { 
$html .= "tt<td></td>rn"; 
} 

if ($i%$cut==$cut-1) { 
$html .= "t</tr>rn"; 
if ($save) { 
$html .= "t<tr><td></td></tr>rn"; 
} 
} 
$i++; 
} 
$html .= "</table>rn"; 
$html .= "<br>".$create; 
$html .= "</body>rn"; 
$html .= "</html>"; 

echo $html; 
?> 


List of Articles
번호 제목 날짜 조회 수
160 PHP의 유동변수!? - $a1 ~ $a2 같은 형식의 변수를 반복문 돌릴때... 2017.03.06 16610
159 PHP웹 보안 취약점 TOP5(웹해킹) 2023.01.12 292
158 PHP와 HTML과 자바스크립트의 관계 2021.03.26 311
157 PHP에서의 대칭 암호화/복호화 ― 간단한 예제에서 DB 입/출력까지 2018.09.14 3548
156 php에서 체크박스 선택한 것 보여주기 file 2019.01.08 1805
155 PHP에서 조건문 처리 2015.04.14 22038
154 PHP에서 자바스크립트 값 가져오기 2014.02.27 31635
153 PHP에서 자료, 데이터의 타입을 확인하는 방법, gettype() 2018.08.29 2447
152 PHP에서 암호화 encrypt 복호화 decrypt 해서 값을 넘기기 2018.02.09 10626
151 PHP에서 모든 세션 정보를 화면에 출력하는 방법 2018.08.29 2693
150 PHP에서 데이터를 엑셀(Excel)로 저장 2017.02.19 18428
149 PHP에서 UTF와 EUC-KR 변환 2019.02.19 1553
148 PHP에서 PDF파일 생성하기 2014.02.27 32777
147 PHP에서 Excel 파일을 만들 수 있는 PHPExcel file 2017.03.06 17112
146 PHP에서 CSV 파일 export file 2016.04.22 22333
145 PHP로 엑셀 자료 MySQL에 넣기 2017.03.06 17875
144 PHP로 Excel 파일 만들기... 2014.02.27 30257
143 php로 db 컨트롤 1 2017.03.06 15769
142 phpMyAdmin WebMysql 에 CSV 엑셀 파일 업로드 입력하기 ( Excel / Upload / data / 데이터 / 데이타 ) file 2021.03.25 754
141 phpexcel을 이용한 PHP로 엑셀파일 읽기와 생성 file 2017.03.06 22787
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved