PHP

지각생 연습장

  • PHP 강좌 : 좋은 강좌, 글, 커리큘럼 등

목차

[편집] 좋은 리소스

[편집] 프레임워크

[편집] PEAR

  • PEAR is a framework and distribution system for reusable PHP components.
  • 패키지 설치
     # pear install <package name>
    • 공용 호스트에 따로 pear 설치하기 (웹 호스팅 받는데 pear 가 안깔려 있을때)
      1. http://pear.php.net/go-pear 를 다운받아 호스트에 업로드. go-pear.php 정도로
      2. 호스트에 접속한 후(ftp, ssh..) 타겟 디렉토리 만듬. 777로 권한 설정
      3. php CLI 알아놓기 (which php -> /usr/local/bin/php 식)
      4. 웹 브라우저로 http://사이트/go-pear.php 접근
      5. pear 패키지 웹관리자로 추가 패키지 설치
        • 보안 처리하는 부분은 관리자의 협조가 필요할듯 (override)
  • DB_DataObject
    • End-User Guide
    • PEAR 패키지 전체를 압축해둠 : http://latecomer.pe.kr/lib_dj.tgz => 사용할 곳에서 압축 풀고 쓰니 되더군. (항상되는 것은 아니군 -_- 2007.12.18)
    • 자동 생성된 테이블 값 이용안하려면
class mytable extends DB_DataObject {
  var $_database_dsn = "mysql://username:password@localhost/database";
  var $__table = "mytable";
  function table() {
    return array(
      'id' => 1, //integer or number
      'name' => 2, // string
    }
  }
  function keys() {
    return array('id');
  }
}

$instance = new mytable;
$instance->get("id", 12);
echo $instance->somedata;

$instance->whereAdd("ID > 12");
$instance->whereAdd("ID < 14"); 
$instance->find();
while($instance->fetch()) {
  echo $instance->somedata;
}

[편집] 정규표현식 모음

  • 웹(ftp) 문서 패턴 : (http|ftp)://([0-9a-zA-Z./@~?&=_]+)
  • 이메일 : ([_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+)*)@([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)

[편집] PHP5 컴파일 설치

[편집] 라이브러리 설치

  • zlib - www.gzip.org/zlib, www.zlib.net. PHP의 zlib 확장 모듈이 제공하는 API를 통해 압축 파일을 읽고 쓸 수 있게 된다.
  • iconv - 문자셋 변환 라이브러리
  • libxml2 - XML문서 파싱 라이브러리, DOM, SAX, XSLT, SimpleXML 과 같은 확장 모듈의 기반
  • libxslt - XML 문서를 다른 구조의 XML 또는 HTML 문서로 변환하는 기능 제공
  • GD 설치

[편집] PHP5 컴파일

  • Configure 옵션
--with-apxs=/usr/local/www/bin/apxs
--with-zlib-dir=/usr/local
--with-iconv-dir=/usr/local
--with-libxml-dir=/usr/local
--with-xsl=/usr/local
--with-config-file-path=/usr/local/www/conf
--with-mod_charset
--enable-sigchild

[편집] PHP로 HTTP인증하기

[편집] 짤막 팁/소스

  • 다른 페이지로 바로 이동 (인덱스 파일 등에서)
     <? header("Location: 옮길위치"); ?>
  • 제로보드 : 썸네일 이미지 표시하기 - 큰 이미지가 업로드되면, 자동으로 일정 폭 기준으로 크기를 변경한 썸네일을 생성하고, 표시한다. 썸네일은 업로드한 이미지를 최초로 열어볼 때 만들어진다.
<?php
	list($image1_width, $image1_height) = getimagesize($data[file_name1]);
	//$image1_width = imagesx($data[file_name1]);
	if($image1_width && $image1_width > 580) $image1_width_new = 580;
	else $image1_width_new = $image1_width;
	//echo $data[file_name1]; echo $image1_width;
	$image1_height_new = round($image1_height * 580 / $image1_width);
	$thumb1 = thumb($id, $data[s_file_name1], 580, $image1_height_new); // x:y = newx: newy => newy = y*newx / x 
 
	$upload_image1 = str_replace("style=\"", "style=\"width: ${image1_width_new}px; ", $upload_image1);
	$upload_image1 = preg_replace("/src=\S+ /", "src=$thumb1 ", $upload_image1);
	if($data[file_name2]) {
		list($image2_width, $image2_height) = getimagesize($data[file_name2]);
 
		if($image2_width && $image2_width > 580) $image2_width_new = 580;
		else $image2_width_new = $image2_width;
 
		$image2_height_new = round($image2_height * 580 / $image2_width);
		$thumb2 = thumb($id, $data[s_file_name2], 580, $image2_height_new); 
		$upload_image2 = str_replace("style=\"", "style=\"width: ${image2_width_new}px; ", $upload_image2);
		$upload_image2 = preg_replace("/src=\S+ /", "src=$thumb2 ", $upload_image2);
	}
?>

[편집] 전자상거래

[편집] 애플리케이션

[편집] 참고

개인 도구