php 5.4 eregi to preg_match

PHP 2016. 1. 27. 17:24


eregi 는 preg_match 로 변경



변경 전 : 

if (eregi("data/cheditor4/{$ym}/[^<>]*\.(gif|jpg|png|bmp)", $edit_img, $tmp)) { 



}



변경 후 :

if (preg_match("/data\/cheditor4\/{$ym}\/[^<>]*\.(gif|jpg|png|bmp)/", $edit_img, $tmp)) { 



}





'PHP' 카테고리의 다른 글

MySQL 트랜잭션  (0) 2016.02.29
php 5.4 number_format  (0) 2016.01.27
php 5.4 split to explode  (0) 2016.01.27
PHP 5.3이상에서 변경되는 함수들  (0) 2015.07.24
php, 아파치 에러로그 Use of undefined constant ~~~  (0) 2015.04.29
블로그 이미지

엘로드넷

,

php 5.4 split to explode

PHP 2016. 1. 27. 17:20

split 함수는 explode 로 변경



추가적인 작업 필요없이 함수만 변경하면된다.


블로그 이미지

엘로드넷

,

PHP 5.3이상에서 변경된 함수들


  • call_user_method()  =>  call_user_func()
  • call_user_method_array() =>  call_user_func_array() 
  • define_syslog_variables()
  • dl()
  • ereg() =>  preg_match() 
  • ereg_replace() =>  preg_replace() 
  • eregi() =>  preg_match() 
  • eregi_replace() =>  preg_replace() 
  • set_magic_quotes_runtime() and its alias, magic_quotes_runtime()
  • session_register() =>  $_SESSION superglobal 
  • session_unregister() => $_SESSION superglobal 
  • session_is_registered() =>  $_SESSION superglobal 
  • set_socket_blocking() =>  stream_set_blocking() 
  • split() =>  preg_split() 
  • spliti() =>  preg_split() 
  • sql_regcase()
  • mysql_db_query() (use mysql_select_db() and mysql_query() instead)
  • mysql_escape_string() (use mysql_real_escape_string() instead)
  • Passing locale category names as strings is now deprecated. Use the LC_* family of constants instead.
  • The is_dst parameter to mktime(). Use the new timezone handling functions instead.


블로그 이미지

엘로드넷

,

php, 아파치 에러로그 Use of undefined constant ~~~



[Wed Apr 29 20:30:12 2015] [error] [client 123.123.123.123] PHP Notice:  Use of undefined constant ~~~~~~~ assumed '



위와 같은 로그가 쌓인다.


프로그램은 잘 작동하고 있다.


자세히 보면 assumed 이하에서처럼 따옴표로 둘러라는 말이 나온다.


디비에서 해당 배열변수에 값을 할당하는 부분을 찾아서 따옴표를 붙여 준다.


아래와 같이.


$sql = "select id, ~~~~~~";

$result = mysql_query($sql);

$data = mysql_fetch_array($result);


원래 : $id = $data[id];

수정 : $id = $data['id'];




끝.


블로그 이미지

엘로드넷

,

php, 아파치 로그 [error] [client xxx.xxx.xxx.xxx] PHP Notice:  Use of undefined index 에러가 쌓일 때.



tail -f error_log 해보면 


[Wed Apr 29 20:30:12 2015] [error] [client 123.123.123.123] PHP Notice:  Undefined index page in /~~~~ 과 같은 로그가 계속 쌓이는 것을 볼 수 있다.


그런데 해당 페이지는 전혀 문제가 없다. 로그만 쌓일 뿐이다.


괜히 로그 파일만 쌓이니 해결해 주자.




원인 : 보통 php변수를 선언할 때엔 변수 선언과 동시에 값을 대입하는데 GET, POST 변수인 경우엔 변수 선언시 아직 값이 할당되지 않은 경우가 있다.


즉, 


1.  $page = $_GET['page'];

2.  if(!$page){

3.     $page = 1;

4.  }


위와 같이 선언한 경우에는 2페이지로 넘어가기 전 1페이지만 호출시 $_GET['page'] 값이 없게 된다. 

그래서 1번줄에 에러가 나는 것이다.


물론 프로그램 동작시에는 문제가 없지만 php설정에 따라 로그를 남기게 된다.


null 값으로 변수를 선언했다는 이유임.



해결방법1) : 변수선언시 isset 으로 확인 (권장방법)


php.net 에서 권고하는 방법은, 변수선언을 다음과 같이 해준다.


1번 행을, 아래와 같이 선언해준다.


1.  $page = (isset($_GET['page']) ? $_GET['page'] : null);



다음과 같이 해도 됨.
$page = (isset($page) ? $page : null);



해결방법2) : php.ini 수정 (권장하진 않지만 동일한 효과)


서버를 손볼 수 있다면 php.ini 파일을 열어 수정해 준다.


php.ini 파일을 열고 아래와 같은 부분을 찾는다.


;error_reporting = E_ALL & ~E_NOTICE

;

;   - Show all errors, except for notices

;

;error_reporting = E_ALL & ~E_NOTICE | E_STRICT

;

;   - Show only errors

;

;error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

;

;   - Show all errors, except coding standards warnings

;

error_reporting  =  E_ALL



이 부분을 아래와 같이 주석을 바꿔준다.




error_reporting = E_ALL & ~E_NOTICE

;

;   - Show all errors, except for notices

;

;error_reporting = E_ALL & ~E_NOTICE | E_STRICT

;

;   - Show only errors

;

;error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

;

;   - Show all errors, except coding standards warnings

;

;error_reporting  =  E_ALL



저장하고 아파치를 재시작하면 된다.


끝.




'PHP' 카테고리의 다른 글

php 5.4 split to explode  (0) 2016.01.27
PHP 5.3이상에서 변경되는 함수들  (0) 2015.07.24
php, 아파치 에러로그 Use of undefined constant ~~~  (0) 2015.04.29
PHP : email주소 유효성 체크  (0) 2015.04.18
PHP 확장자 구하기  (0) 2015.04.18
블로그 이미지

엘로드넷

,
email주소 유효성 체크 :

$email = $_POST['email'];

if (trim($email)=='') { echo "이메일을 입력해 주십시오."; } else if (!preg_match("/([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/", $email)) { echo "올바른 이메일 형식이 아닙니다."; } else { echo "올바른 이메일입니다."; }



블로그 이미지

엘로드넷

,

PHP 확장자 구하기

PHP 2015. 4. 18. 08:16
PHP확장자 구하기 :

$fileInfo = pathinfo('/home/www/index.html');
$fileExt = $fileInfo['extension'];
echo "파일의 확장자는 ".$fileExt;


블로그 이미지

엘로드넷

,