본문으로 바로가기

Error : PHP Deprecated:  Function ereg_replace() is deprecated in ..

원인 : php5.3부터 ereg_repalce라는 함수가 배제되었다.

해결방법 : preg_repalce 함수 사용


 - ereg_replace("찾는값", "치환값", "문자열") 

   : 문자열 중 찾는 값이 나오면 치환 값으로 치환한다.

   : 참고) eregi_replace($pattern, $replacement , $subject) : eregi_repalce()함수와 같으나 대소문자 구분

 - preg_replace($pattern, $replacement , $subject)

   : subject를 검색하여 매치된 pattern을 replacement로 치환합니다.


[ 이외 ] 

 - ereg -> preg_match

 - preg_match("pattern", "subject")

   : pattern에 주어진 정규표현식을 subject에서 찾는다.

   : 예) 

$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches); 

//출력값
//Array
//(
//    [0] => Array
//        (
//            [0] => def
//            [1] => 0
//        )
//)


* 참고 사이트

 : http://www.php.net/manual/kr/function.preg-match.php

 : http://php.net/manual/kr/function.preg-replace.php