정규표현식 - 특정 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);
[Crawler] 특정 값 파싱 안될 때(ex. 작성자)
·
Development
특정 값 안나올 때 (ex. 작성자, 날짜 등)사이트내의 `network`에 검색했을 때도 안나오는 값일 경우,정상적으로 웹 파싱이 안되어서 값을 못불러오는 경우 일 수 있음. 그럴 경우 파싱넘겨주는 값을 수정한다1. `path` 추가2. `user-agent` 변경 (4.0 => 5.0)3. `cookie`값 추가 해주었더니 정상적으로 모든 값이 파싱됨.$strParseContent = "";$strParseContent .= "GET"; // POST, GET 선택$strParseContent .= " {$strParseSubURL} HTTP/1.0\r\n"; // 도메인이외의 파라미터값.$strParseContent .= "Host:{$strParseHost}\r\n"; // "http://" 제거..
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..