function get_token_file_info() {
   // Set File Path
  $filename = file_path;

   // File Open by Read Mode
  $ofile = fopen($filename, 'r');

   // Get File text
  $token_value = fgets($ofile);

   // Get File modify time
   // Timestamp 값을 받아 오는데 msec 값을 제외한 10자리로 받아 온다.
   // Javascript 에서는 13자리를 받기 때문에 뒤에 000 을 붙여서 주는 방법도 있음
  $token_time = filemtime($filename);

   // Get Current Time
  $current_time = time();

  $result['token_value'] = $token_value;
  $result['token_time'] = $token_time;
  $result['current_time'] = $current_time;

  $this->output->set_content_type ( 'application/json' )->set_output ( json_encode ( $result ) );
}


'WEB개발 > php' 카테고리의 다른 글

[php] curl POST/GET 처리 예제  (0) 2019.01.07
[php] socket client 처리  (0) 2019.01.07
[php] array로 return 시 list로 받아오기  (0) 2019.01.07
[php] array 관련 함수  (0) 2019.01.07
[php] foreach 반복문  (0) 2019.01.07

버튼 클릭 시 Table의 td 값을 Clipboard에 복사 하기

[ CSS ]
.hidden {
   position: fixed;
   bottom: 0;
   right: 0;
   pointer-events: none;
   opacity: 0;
   transform: scale(0);
}


[ HTML ]
<tr>
  <td class="">UserName</td>
  <td id="username" class="username">1234567</td>
  <td>
        <button style="display:inline" id="copy_username" type="button" class="btn btn-warning">copy</button>
        <input class="clipboard hidden" />
    </td>
</tr>

[ Javascipt ]
$("#copy_username").click(function() {
   var aux = document.createElement("input");
   copyText = document.getElementById("username").innerHTML;

   // Get the text from the element passed into the input
   aux.setAttribute("value", copyText);

   // Append the aux input to the body
   document.body.appendChild(aux);

   // Highlight the content
   aux.select();

   // Execute the copy command
   document.execCommand("copy");

   // Remove the input from the body
   document.body.removeChild(aux);

   alert('Copy Username to Clipboard : ' + copyText );
});



CodeIgniter의 상수는 application/config/constants.php에 정의


vi application/config/constants.php

define('FOPEN_READ', 'rb');



view, controller, model에서 아래와 같이 바로 사용할 수 있다.


<body>
    <div id="container">

        <p>FOPEN_READ : <?php echo FOPEN_READ;?></p>     </div> </body>



'WEB개발 > CodeIgniter' 카테고리의 다른 글

[CodeIgniter] 초기 접속 위치 변경  (0) 2019.01.04
[CodeIgniter] 초기 설치 방법  (0) 2019.01.04
    function execute( $url_segment, $data, $excute_type, $is_info_log = false ) {
		$curl = curl_init();

		curl_setopt($curl, CURLOPT_URL, .$url_segment);
                // $excute_type = 'POST' or 'GET' 
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $excute_type);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
		// curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
		curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
		//curl_setopt($curl, CURLOPT_TIMEOUT, CUR_TIMEOUT);

		/*curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($curl, CURLOPT_SSLVERSION,3);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
		*/

		$result = curl_exec($curl);
		curl_close( $curl );
		log_message('error', 'url:'.$url_segment.', data:'. json_encode($data).' result1:'.$result );

		$obj = json_decode( $result, true );
		$log_level = 'error';
		if( $is_info_log ) {
			$log_level = 'info';
		}
		log_message($log_level, 'url:'.$url_segment.', data:'. json_encode($data).' result:'.$result );
		return $obj;
	}
    function execute_socket( $url_segment, $port, $data, $is_info_log = false ) {
		# SOL_TCP =0 , SOL_UDP = 1
		$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

		if ($sock === false) {
			$obj = "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
			return $obj;
		}

		if (($result = (socket_connect($sock, $url_segment, $port))) === false) {
			$obj = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($sock)) . "\n";
			return $obj;
		} else {
			socket_write($sock, json_encode($data));
			$obj = socket_read($sock, 1024);
			socket_close($sock);
			
			$log_level = 'error';
			if( $is_info_log ) {
				$log_level = 'info';
			}

			log_message($log_level, 'url:'.$url_segment.', port:'.$port.', data:'. json_encode($data).' result:'.$obj );
			return $obj;
		}
	}
    list ($table_list, $prd_total) = $this->_make_item($list);

    function _make_item ($list) {
        $ret = array();
        $prd_total = 0;
        foreach ($list as $idx=>$item) {
            $_item['PRD_DATE'] = $item->PRD_DATE;
            if ( isset ($item->SEQ)) {
                $_item['SEQ'] = $item->SEQ;
            } else {
                $_item['SEQ'] = '-';
            }
            $_item['PRD_QTY'] = $item->PRD_QTY;
            $_item['LOSS_QTY'] = $item->LOSS_QTY;
            $suyul = round($_item['PRD_QTY'] / ($_item['PRD_QTY'] + $_item['LOSS_QTY']) * 100, 2);
            $_item['SUYUL'] = round($suyul, 2);
            array_push($ret, $_item );
            $prd_total += $item->PRD_QTY;
        }
        return array($ret, $prd_total);
    }

'WEB개발 > php' 카테고리의 다른 글

[PHP] 파일의 내용이랑 파일 수정 시간 가져오기  (0) 2019.02.27
[php] curl POST/GET 처리 예제  (0) 2019.01.07
[php] socket client 처리  (0) 2019.01.07
[php] array 관련 함수  (0) 2019.01.07
[php] foreach 반복문  (0) 2019.01.07

배열 함수 목록

  • array_change_key_case — 배열 안의 모든 키를 변경
  • array_chunk — 배열을 조각으로 나누기
  • array_column — Return the values from a single column in the input array
  • array_combine — 키를 위한 배열과 값을 위한 배열을 사용하여 배열을 생성
  • array_count_values — 배열 값의 수를 셉니다
  • array_diff_assoc — 추가적인 인덱스 확인과 함께 배열 차이를 계산
  • array_diff_key — Computes the difference of arrays using keys for comparison
  • array_diff_uassoc — Computes the difference of arrays with additional index check which is performed by a user supplied callback function
  • array_diff_ukey — Computes the difference of arrays using a callback function on the keys for comparison
  • array_diff — 배열 차이를 계산
  • array_fill_keys — Fill an array with values, specifying keys
  • array_fill — 값으로 배열 채우기
  • array_filter — 콜백 함수를 사용하여 배열 원소를 필터
  • array_flip — 배열 안의 모든 키를 키의 연관 값과 교체
  • array_intersect_assoc — 인덱스 검사과 함께 배열의 교집합을 계산
  • array_intersect_key — Computes the intersection of arrays using keys for comparison
  • array_intersect_uassoc — Computes the intersection of arrays with additional index check, compares indexes by a callback function
  • array_intersect_ukey — Computes the intersection of arrays using a callback function on the keys for comparison
  • array_intersect — 배열의 교집합을 계산
  • array_key_exists — 주어진 키와 인덱스가 배열에 존재하는지 확인
  • array_keys — 배열의 모든 키를 반환
  • array_map — Applies the callback to the elements of the given arrays
  • array_merge_recursive — 두개 이상의 배열을 재귀적으로 병합
  • array_merge — 하나 이상의 배열을 병합
  • array_multisort — 여러 배열이나 다차원 배열 정렬
  • array_pad — 지정한 길이만큼 특정 값으로 배열 채우기
  • array_pop — 배열의 마지막 원소 빼내기
  • array_product — Calculate the product of values in an array
  • array_push — 배열의 끝에 하나 이상의 원소를 넣는다
  • array_rand — 배열에서 하나 이상의 임의 원소를 가져옴
  • array_reduce — 콜백 함수를 사용하여 배열을 반복적으로 단일 값으로 축소
  • array_replace_recursive — Replaces elements from passed arrays into the first array recursively
  • array_replace — Replaces elements from passed arrays into the first array
  • array_reverse — 원소를 역순으로 가지는 배열을 반환
  • array_search — 주어진 값으로 배열을 검색하여 성공시 해당하는 키를 반환
  • array_shift — 배열의 앞에 있는 원소를 시프트
  • array_slice — 배열의 일부를 추출
  • array_splice — 배열의 일부를 삭제하고, 위치를 다른 내용으로 대체
  • array_sum — 배열 값들의 합을 계산
  • array_udiff_assoc — Computes the difference of arrays with additional index check, compares data by a callback function
  • array_udiff_uassoc — Computes the difference of arrays with additional index check, compares data and indexes by a callback function
  • array_udiff — 데이터 비교 콜백함수를 사용하여 배열간의 차이를 계산
  • array_uintersect_assoc — Computes the intersection of arrays with additional index check, compares data by a callback function
  • array_uintersect_uassoc — Computes the intersection of arrays with additional index check, compares data and indexes by separate callback functions
  • array_uintersect — Computes the intersection of arrays, compares data by a callback function
  • array_unique — 배열에서 중복된 값을 제거
  • array_unshift — 배열의 앞에 하나 이상의 원소를 첨가
  • array_values — 배열의 모든 값을 반환
  • array_walk_recursive — Apply a user function recursively to every member of an array
  • array_walk — 배열의 원소에 대해서 특정 함수를 적용
  • array — 배열 생성
  • arsort — 배열을 내림차순 정렬하고 인덱스의 상관관계를 유지
  • asort — 배열을 정렬하고 인덱스 상관 관계를 유지
  • compact — 변수와 값을 가지는 배열 생성
  • count — 배열의 모든 원소나, 객체의 프로퍼티 수를 셉니다
  • current — 배열의 현재 원소를 반환
  • each — 배열에서 현재 키와 쌍을 반환하고 배열 커서를 전진
  • end — 배열 내부 포인터가 마지막 원소를 가리키게 설정
  • extract — 배열에서 현재 심볼 테이블로 변수를 입력
  • in_array — 값이 배열 안에 존재하는지 확인
  • key_exists — 별칭: array_key_exists
  • key — 배열에서 키를 가져옵니다
  • krsort — 키에 의한 배열 역순 정렬
  • ksort — 키에 의한 배열 정렬
  • list — 배열처럼 변수에 할당
  • natcasesort — "자연순" 알고리즘으로 대소문자를 구분하지 않고 배열 정렬
  • natsort — "자연순" 알고리즘으로 배열 정렬
  • next — 배열의 내부 배열 포인터를 전진
  • pos — 별칭: current
  • prev — 내부 배열 포인터를 후진
  • range — 원소의 범위를 가지는 배열 생성
  • reset — 배열의 내부 포인터를 원소로 설정
  • rsort — 역순으로 배열 정렬
  • shuffle — 배열을 섞습니다
  • sizeof — 별칭: count
  • sort — 배열 정렬
  • uasort — 사용자 정의 비교 함수로 배열을 정렬하고 인덱스 연관성을 유지
  • uksort — 사용자 정의 비교 함수를 사용하여 키에 의한 배열 정렬
  • usort — 사용자 정의 비교 함수를 사용하여 값에 의한 배열 정렬


출처 : http://php.net/manual/kr/book.array.php

$ret = array(); # $arr = array( # array( "CUSTOM" => "1" , "CUSTNM" => "a" ) , # array( "CUSTOM" => "2" , "CUSTNM" => "b") #) foreach( $arr as $idx => $row ) { $ret[$row->CUSTOM] = $row->CUSTNM; } # $ret = array( # array("1" => "a"), # array("2" => "b") #) return $ret;


+ Recent posts