728x90
반응형

PHP 91

[PHP] 여러 특정 문자 기준 배열 preg_split()

■ PHP 여러 특정 문자 기준 배열 preg_split() * PHP 7 이상 split() 함수가 작동되지 않음 ■ 사용법 $tmp_title = "나프탈렌 대용량 벌크 좀약 뱀퇴치,멧돼지/과수농가/방충제 노린재"; # 위와 같은 문자열에서 띄어쓰기(공백), 콤마(,), 슬래시(/) 문자 기준으로 배열 생성 방법 $tmp_title = "나프탈렌 대용량 벌크 좀약 뱀퇴치,멧돼지/과수농가/방충제 노린재"; $tmp_test = preg_split('/([\/, \r\n|\r|\n])/', $tmp_title, -1); print_r($tmp_test); /* Array ( [0] => 나프탈렌 [1] => 대용량 [2] => 벌크 [3] => 좀약 [4] => 뱀퇴치 [5] => 멧돼지 [6] => 과..

PHP 2021.04.13

[PHP] 엑셀(excel) 파일 읽기

■ PHP 엑셀(excel) 파일 읽기 ■ 사용법 require_once "./PHPExcel-1.8/Classes/PHPExcel.php"; // PHPExcel.php 로드 $objPHPExcel = new PHPExcel(); // 엑셀 데이터를 담을 배열을 선언한다. $excelData = array(); // 파일의 저장형식이 utf-8일 경우 한글파일 이름은 깨지므로 euc-kr로 변환해준다. $filename = iconv("UTF-8", "EUC-KR", $_FILES['excelFile']['name']); try { // 업로드한 PHP 파일을 읽어온다. $objPHPExcel = PHPExcel_IOFactory::load($filename); $sheetsCount = $objPHP..

PHP 2021.04.01

[PHP] 특정 디렉토리 내 파일 삭제 unlink() / 파일 리스트 opendir(), readdir()

■ PHP 특정 디렉토리 내 파일 삭제, php 폴더 내 파일 삭제 unlink() / 파일 리스트 opendir(), readdir() ■ 사용법 특정 디렉토리 내 모든 파일 삭제 $directory = "/www/upload/"; $handle = opendir($directory); // 절대경로 if( is_dir($directory) ){ if( $handle ){ while( ($filerd = readdir($handle)) != false ){ if( $filerd != ".." && $filerd != "." ){ //echo $directory.$filerd; @unlink($directory.$filerd); } } } } closedir($handle); 특정 디렉토리 내 특정 확장..

PHP 2021.03.30

[PHP] 이미지 리사이즈 (크기변경, 썸네일생성)

■ PHP 이미지 리사이즈 (크기변경, 썸네일생성) / 이미지 크기변경 / 이미지 썸네일 생성 ■ 함수 정의 function resize_image($file, $newfile, $w, $h) { list($width, $height) = getimagesize($file); if(strpos(strtolower($file), ".jpg")) $src = imagecreatefromjpeg($file); else if(strpos(strtolower($file), ".png")) $src = imagecreatefrompng($file); else if(strpos(strtolower($file), ".gif")) $src = imagecreatefromgif($file); $dst = imagecrea..

PHP 2021.03.30

[PHP] 외부이미지 서버 저장 / php curl 이미지 저장

■ PHP 외부이미지 서버 저장 / php curl 이미지 저장 ■ 사용법 $imgLink = "https://test_imglink.co.kr/test.jpg"; // 파일명 가져오기 $linkArray = explode("/", $imgLink); $filename = $linkArray[count($linkArray)-1]; // 확장자명 가져오기 //$ext = strtolower(pathinfo($imgLink, PATHINFO_EXTENSION));// jpg // 저장할 이미지 위치 및 파일명 $fp = fopen("./upload/".$filename,'w'); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $imgLink); curl_setopt..

PHP 2021.03.30

[PHP] curl 사용법 (GET,POST) / REST API 요청

■ PHP curl 사용법 (GET,POST) / REST API 요청 ■ 사용법 GET $method = "GET"; $data = array( 'apiKey' => 'test' ); $url = "https://www.naver.com" . "?" , http_build_query($data, '', ); $ch = curl_init(); //curl 초기화 curl_setopt($ch, CURLOPT_URL, $url); //URL 지정하기 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //요청 결과를 문자열로 반환 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //connection timeout 10초 curl_setop..

PHP 2021.03.30

[PHP] 문자열 공백제거 / 문자열 앞뒤 공백제거 trim() / 문자열 모든 공백제거 preg_replace()

■ PHP 문자열 공백제거 / 문자열 앞뒤 공백제거 trim() / 문자열 모든 공백제거 preg_replace() ■ 사용법 trim($string); // 문자열의 앞뒤 공백 제거 $tmpString = " a b c d e "; $outString = trim($tmpString); echo $outString;// "a b c d e" preg_replace("/\s+/", "", $string); // 문자열의 모든 공백 제거 $tmpString = " a b c d e "; $outString = preg_replace("/\s+/", "", $tmpString); echo $outString;// "abcde"

PHP 2021.03.30
728x90
반응형