<?php
// PHP변수 스크립트에서 쉽게 사용하기
function setScriptVar($name, $obj) {
global $script;
$script = "<script language='javascript'>";
if(is_object($obj)) {
$script .= "var $name = new Array();";
factory($name, $obj,'object');
} elseif(is_array($obj)) {
$script .= "var $name = new Array();";
factory($name, $obj,'array');
} else {
if(is_numeric($obj)) $script .= "var $name = $obj;";
else $script .= "var $name = '$obj';";
}
$script .= "</script>";
echo $script;
}
function factory($name, $data, $type = NULL) {
global $script;
foreach($data as $key => $val) {
if(is_object($val)){
factory($name.".".$key, $val, 'object');
} elseif(is_array($val)){
if($type == 'array') {
$script .= $name."[".$key."] = new Array();";
factory($name."[".$key."]", $val, 'array');
} else {
$script .= $name.".".$key." = new Array();";
factory($name.".".$key, $val, 'array');
}
} elseif(preg_match("/[a-zA-Z_][a-zA-Z0-9_]*/",$key) && $type == 'object') {
if(is_numeric($val)) $script .= $name.".".$key."=".$val.";";
else $script .= $name.".".$key."='".$val."';";
} elseif($type == 'array') {
if(!is_numeric($key)) $key = "'".$key."'";
if(is_numeric($val)) $script .= $name."[".$key."]=".$val.";";
else $script .= $name."[".$key."]='".$val."';";
}
}
}
// 사용법 setScriptVar(변수명지정,PHP변수);
// 일반변수
$market = "I Like Fruit!";
setScriptVar("market", $market);
// 배열
$fruit = array('Apple','Pineapple',array('Tomato','Banana'));
setScriptVar("fruit", $fruit);
// 오브젝트와 배열
$list->like = 'Pineapple';
$list->hate = 'Tomato';
$list->buy = array('Apple','Pineapple');
setScriptVar("list", $list);
// 변수타입
$num = array(100,'200');
setScriptVar("num",$num);
?>
<script>
//alert(market); // I Like Fruit!
//alert(fruit[0]+"/"+fruit[2][0]); // Apple/Tomato
//alert(list.like+"/"+list.buy[0]); // Pineapple/Apple
//alert(num[0] + 10); // 110
//alert(num[1] + 10); // 20010
</script>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6730 |
|
11년 전 | 1113 | |
| 6729 | 11년 전 | 568 | ||
| 6728 |
|
11년 전 | 582 | |
| 6727 | 11년 전 | 2426 | ||
| 6726 | 11년 전 | 602 | ||
| 6725 |
네모웹에이전시
|
11년 전 | 447 | |
| 6724 |
네모웹에이전시
|
11년 전 | 890 | |
| 6723 | 11년 전 | 1026 | ||
| 6722 | 11년 전 | 969 | ||
| 6721 | 11년 전 | 653 | ||
| 6720 | 11년 전 | 1978 | ||
| 6719 | 11년 전 | 2199 | ||
| 6718 | 11년 전 | 1111 | ||
| 6717 |
|
11년 전 | 664 | |
| 6716 | 11년 전 | 2311 | ||
| 6715 | 11년 전 | 7582 | ||
| 6714 | 11년 전 | 2050 | ||
| 6713 | 11년 전 | 788 | ||
| 6712 |
geektoo
|
11년 전 | 1161 | |
| 6711 | 11년 전 | 904 | ||
| 6710 |
sirzzang
|
11년 전 | 2135 | |
| 6709 |
bewitched
|
11년 전 | 1804 | |
| 6708 |
levin
|
11년 전 | 574 | |
| 6707 | 11년 전 | 769 | ||
| 6706 | 11년 전 | 1801 | ||
| 6705 | 11년 전 | 994 | ||
| 6704 |
|
11년 전 | 759 | |
| 6703 | 11년 전 | 420 | ||
| 6702 | 11년 전 | 1102 | ||
| 6701 | 11년 전 | 808 | ||
| 6700 | 11년 전 | 1723 | ||
| 6699 | 11년 전 | 717 | ||
| 6698 |
이박사친구
|
11년 전 | 732 | |
| 6697 | 11년 전 | 1220 | ||
| 6696 | 11년 전 | 622 | ||
| 6695 |
Header
|
11년 전 | 708 | |
| 6694 | 11년 전 | 1165 | ||
| 6693 |
|
11년 전 | 1116 | |
| 6692 | 11년 전 | 1153 | ||
| 6691 | 11년 전 | 1290 | ||
| 6690 |
|
11년 전 | 721 | |
| 6689 | 11년 전 | 898 | ||
| 6688 | 11년 전 | 938 | ||
| 6687 | 11년 전 | 542 | ||
| 6686 |
RGB255
|
11년 전 | 964 | |
| 6685 |
|
11년 전 | 645 | |
| 6684 | 11년 전 | 722 | ||
| 6683 | 12년 전 | 389 | ||
| 6682 | 12년 전 | 1134 | ||
| 6681 | 12년 전 | 1427 | ||
| 6680 | 12년 전 | 460 | ||
| 6679 |
RGB255
|
12년 전 | 399 | |
| 6678 | 12년 전 | 1353 | ||
| 6677 |
|
12년 전 | 445 | |
| 6676 | 12년 전 | 1018 | ||
| 6675 |
디자이너필이
|
12년 전 | 828 | |
| 6674 | 12년 전 | 1243 | ||
| 6673 | 12년 전 | 1316 | ||
| 6672 | 12년 전 | 6034 | ||
| 6671 | 12년 전 | 1343 | ||
| 6670 |
하프의정령
|
12년 전 | 576 | |
| 6669 | 12년 전 | 418 | ||
| 6668 |
공부하고가겠슴다
|
12년 전 | 464 | |
| 6667 |
하프의정령
|
12년 전 | 553 | |
| 6666 | 12년 전 | 790 | ||
| 6665 | 12년 전 | 1415 | ||
| 6664 | 12년 전 | 936 | ||
| 6663 | 12년 전 | 1160 | ||
| 6662 | 12년 전 | 415 | ||
| 6661 |
basketball
|
12년 전 | 514 | |
| 6660 | 12년 전 | 2514 | ||
| 6659 | 12년 전 | 1616 | ||
| 6658 |
|
12년 전 | 1340 | |
| 6657 |
|
12년 전 | 3162 | |
| 6656 | 12년 전 | 566 | ||
| 6655 |
프로프리랜서
|
12년 전 | 2336 | |
| 6654 |
프로프리랜서
|
12년 전 | 1915 | |
| 6653 |
프로프리랜서
|
12년 전 | 1749 | |
| 6652 |
프로프리랜서
|
12년 전 | 1835 | |
| 6651 |
|
12년 전 | 787 | |
| 6650 | 12년 전 | 1320 | ||
| 6649 | 12년 전 | 1320 | ||
| 6648 | 12년 전 | 814 | ||
| 6647 | 12년 전 | 3164 | ||
| 6646 | 12년 전 | 474 | ||
| 6645 | 12년 전 | 968 | ||
| 6644 |
BBAYOUNG
|
12년 전 | 1393 | |
| 6643 | 12년 전 | 1804 | ||
| 6642 | 12년 전 | 650 | ||
| 6641 | 12년 전 | 1341 | ||
| 6640 | 12년 전 | 718 | ||
| 6639 | 12년 전 | 2323 | ||
| 6638 |
jasmin2
|
12년 전 | 759 | |
| 6637 |
geektoo
|
12년 전 | 447 | |
| 6636 | 12년 전 | 670 | ||
| 6635 |
프로프리랜서
|
12년 전 | 2236 | |
| 6634 |
프로프리랜서
|
12년 전 | 1743 | |
| 6633 |
프로프리랜서
|
12년 전 | 4060 | |
| 6632 |
프로프리랜서
|
12년 전 | 1350 | |
| 6631 |
프로프리랜서
|
12년 전 | 1790 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기