정규표현식 - 특정 HTML 태그 제거하기
·
Development/PHP
해당 태그 및 태그의 내용을 모두 제거한다. #style 태그 제거 $strContents = preg_replace('@
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
텍스트 변환(str_replace)
·
Development
# `(') $strContents = str_replace("'", "`", $strContents); # $strContents = str_replace(" ", " ", $strContents);
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);