메뉴 건너뛰기

프로그램언어

조회 수 25438 추천 수 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; 
?> 


  1. No Image 27Feb
    by
    2014/02/27 Views 30280 

    무조건 알아야 할 PHP 속도 테스트 14 가지

  2. No Image 07Mar
    by
    2017/03/07 Views 18471 

    몫과 나머지 구하기

  3. No Image 06Mar
    by
    2017/03/06 Views 15508 

    메일주소의 골뱅이를 그림처리하기

  4. No Image 08Jan
    by
    2019/01/08 Views 2000 

    메모장소스

  5. No Image 19Jun
    by
    2020/06/19 Views 438 

    멀티 파일다운로드 꽁수로 구현하기

  6. No Image 24Jul
    by
    2018/07/24 Views 4584 

    마우스 오버시 사진변환, 파일에러시 대체이미지 적용(소스일부)

  7. No Image 23Dec
    by
    2016/12/23 Views 19019 

    링크를 걸때 http 처리방법

  8. No Image 27Feb
    by
    2014/02/27 Views 19386 

    리스트 페이징

  9. No Image 07Mar
    by
    2017/03/07 Views 40215 

    리다이렉션(페이지 이동)의 3가지 방법, location.href

  10. No Image 27Feb
    by 조쉬
    2014/02/27 Views 25438 

    로또 숫자 랜덤하게 1~45까지 숫자 빼오기

  11. No Image 23Dec
    by
    2016/12/23 Views 18847 

    로그인페이지에서 온 경우/로그인한 페이지로 이동

  12. No Image 08Jan
    by
    2019/01/08 Views 1391 

    디비내용을 엑셀 파일로 다운로드 시키는 방법

  13. No Image 08Jan
    by
    2019/01/08 Views 1222 

    디렉토리의 제어

  14. 디렉토리내 특정 확장자를 가진 파일 전부 삭제

  15. No Image 23Dec
    by
    2016/12/23 Views 19012 

    디렉토리 안의 파일의 내용들을 읽는 예

  16. No Image 07Mar
    by
    2017/03/07 Views 18866 

    두 날짜 사이의 차이 구하기

  17. No Image 07Mar
    by
    2017/03/07 Views 18885 

    도메인 앞에 자동으로 WWW를 붙이는 방법

  18. No Image 23Dec
    by
    2016/12/23 Views 19658 

    대소문자 바꾸기 (strtoupper, strtolower)

  19. No Image 08Jan
    by
    2019/01/08 Views 1251 

    단어필터링

  20. 다중파일 업로드 + 이미지 미리보기 (Javascript, jQuery )

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved