CI 묻고 답하기

제목 문자열에서 필요한 문자열만 가져오는 방법..
글쓴이 탄감자 작성시각 2010/01/05 19:59:56
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 21707   RSS
안녕하세요~ 오랜만에 왔네요..^^

질문이 하나 있어서 글 남겨요..

질문내용은 다음과 같은 문자열에서 특정 문자열 뒤에 나오는 문자열을 가져오는 건데요.

예를 들어서..

=========================문자열 내용==========================
이미지 데이터 <img alt="" width="100" height="66" src="/edu_nfs01/common/bbs/img_data/mgr_129/bbs_20100105194342.jpg" /> 이거와 또 다른 이미지 <img alt="" width="100" height="66" src="/edu_nfs01/common/bbs/img_data/mgr_129/bbs_20100105194512.jpg" /> 이 있다.
========================문자열 내용 끝==========================

이런 문자열이 있는데요 여기서 mgr_129/이거 뒤에 나오는 jpg 의 이름을 가져오는 것입니다. jpg의 이름의 길이는 고정 되어 있고요. 문자열의 길이는 랜덤 입니다. jpg는 무조건 mgr_129/ 뒤에 나오게 되어 있습니다.
여러개의 jpg 이름을 모두 가져 올수 있는 방법이 있을까요?

 다음글 [초보]가짜 도메인 질문 (4)
 이전글 popup창에서 부모창에 값넘기기..? (5)

댓글

변종원(웅파) / 2010/01/05 21:04:41 / 추천 0

포럼소스에 있는 내용인데 참고하세요.

 

/**
    * 내용중에서 이미지명 추출후 DB 입력, 파일갯수 리턴. fckeditor용
    */
    function strip_image_tags_fck($str, $no, $type, $table, $table_no)
	{
		$CI =& get_instance();
		$file_table="files";
		preg_match_all("<img [^<>]*>", $str, $out, PREG_PATTERN_ORDER);
		$strs = $out[0];
		//$arr=array();
		$cnt = count($strs);
		for ($i=0;$i<$cnt;$i++) {
  			$arr = preg_replace("#img\s+.*?src\s*=\s*[\"']\s*\/data/images/\s*(.+?)[\"'].*?\/#", "\\1", $strs[$i]);
  			$data = array(
			  			'module_id'=> $table_no,
						'module_name'=> $table,
						'module_no'=>$no,
						'module_type'=>$type,
						'file_name'=>$arr,
  						'reg_date'=>date("Y-m-d H:i:s")
			  			);
			if ( count($arr) <= 25 ) {
				$CI->db->insert($file_table, $data);
			}

  		}
		return $cnt;
	}
jois / 2010/01/07 00:37:55 / 추천 0
 오랜만에 글 하나 남깁니다...

preg_match_all('/mgr_129\/([^ "]+)/', $str, &$matches);
var_dump($matches[1]);