Out of memory 메모리 부족
·
Development/PHP
Fatal error: Out of memory (allocated 4194304) (tried to allocate 232471 bytes) in 파일명.php on line 697 PHP 소스코드에 아래 코드 추가 메모리 무제한 설정 ini_set('memory_limit','-1');
유니코드 변환(decode)
·
Development/PHP
# unicode decode function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'UTF-8');; } # use $str = utf8_urldecode($str); 참고 : https://www.php.net/manual/en/function.urldecode.php
Passed variable is not an array or object
·
Development/PHP
Warning: reset(): Passed variable is not an array or object in 경로/파일명.php on line 1027 전달된 변수가 배열 또는 개체가 아닙니다.
MySQL 연결 및 한글 깨질 경우
·
Development/PHP
php 출력에서 한글이 깨질 경우 아래 set 넣어주기 mysql_query ( 'set names utf8' );
날짜변환
·
Development/PHP
날짜를 변환하고 싶을 때 아래 처럼 해주면 된다. 기본 try { $strDate = new DateTime($strDate); } catch(Exception $e) { echo" \n 날짜변환 오류"; } $strDate = @date_format($strDate, 'Y-m-d'); @date_format 에서 원하는 양식으로 날짜를 변환할 수 있다. Y-m-d로 변환하면 2022-06-30이 나오게 된다. ex. Y.m.d => 2022.06.30 / Ymd => 20220630 / ymd => 220630 ... # 2021-12-22T11:00:44+00:00 # 2021-12-22T11:00:44+00:00 // 1 $strDate = explode('+', $strDate[1]); $strD..
[정규표현식] 정규식 문자열 제거(영문/숫자)
·
Development/PHP
숫자만 남기기 : 숫자를 제외한 모든 문자 제거 $text = preg_replace("/[^0-9]*/s", "", $text); 영어만 제거 $strDate = preg_replace("/[a-z]/i", "", $strDate);
정규식 html 태그제거
·
Development/PHP
preg_replace() 함수를 이용해서 정규식 치환하기 $strContent = preg_replace("(\]+)\>)", "", $strContent); # 모든 태그 제거 ( 공백으로 치환) $strContents_cp = preg_replace("(\]+)\>)", " ", $strContents_cp); # 치환 후 공백제거(2칸 이상인 공백 한칸으로 변경) $strContents_cp = preg_replace("/\s{2,}/"," ",$strContents_cp);
정규식 공백제거(str_replace, preg_replace)
·
Development/PHP
# 모든 태그 제거 $strContents = preg_replace("(\]+)\>)", "", $strContents); # 한칸 이상 공백 제거 $strContents = preg_replace("/\s{2,}/"," ",$strContents); # 탭키 제거 $strContents = str_replace("\t", "", $strContents); # ` $strContents = str_replace("'", "`", $strContents); # &nbsp $strContents = str_replace(" ", " ", $strContents); 1번째 코드 주로 사용하나, 가끔 공백(탭)이 제거가 안된다. $strBody = str_replace("\r", "", str_rep..