사이트 내 전체검색
정규식 문자열 내 이미지,링크 추출하기
로빈아빠
https://cmd.kr/javascript/833 URL이 복사되었습니다.

본문

// a 링크만 추출하기
preg_match_all("|<a[^>]+>(.*)</a>|U",$str,$out1, PREG_PATTERN_ORDER); 
preg_match_all("|<a[^>]+>.*</a>|U",$str,$out2, PREG_PATTERN_ORDER); 
preg_match_all("^<a.*<\/a>^U", $str, $out3);

// http 로 시작하는 것만추출
preg_match_all("((http)://[a-z0-9-]+.[][a-zA-Z0-9:&#@=_~%;?/.+-]+)",$str,$out4, PREG_PATTERN_ORDER); 

// 이미지만 추출
preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", $str, $out5);

echo "<pre>";
print_r ($out1);
print_r ($out1);
print_r ($out1);
print_r ($out1);
print_r ($out1);
print_r ($out1);


preg_match("((http)://[a-z0-9-]+.[][a-zA-Z0-9:&#@=_~%;?/.+-]+)", $item[description], $match);// http로 시작하는 것만 추출
preg_match("/<img[^>]*src="[\']?([^>\"']+)[\"']?[^>]*>/i",$item[description],$match);//이미지만 추출
preg_match("/http:\/\/.*\.(jp[e]?g|gif|png)/Ui",$item[description],$match);//처음 이미지만 추출

RSS뷰어제작시 본문에서 이미지 추출만 추출할때 사용.

댓글목록

등록된 댓글이 없습니다.

831 (1/17P)

Search

Copyright © Cmd 명령어 18.225.8.35