html 코드내에서,
링크를 세부분으로 나누어 추출하려고 합니다.
다음과 같은 html 내용이 있을때,
**************************************************************
<a target=_blank href='http://www.naver.com'>네이버</a>
<area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
**************************************************************
1. <a 혹은 <area 태그 내용
(예: <a target=_blank href='http://www.naver.com'> )
2. 1내용중 href의 내용
(href내용은 큰따옴표 혹은 작은따옴표로 감싸지거나 그냥 링크만 있을수도..)
3. <a 혹은 <area 의 텍스트내용
(위 html의 첫째줄에서는 네이버, 둘째줄에서는 공백이 되겠네요.)
이 세 내용을 preg_match_all 함수와 정규식을 이용해 추출하고자 하는데,
정규식 작성이 잘 되지 않네요..
고수님들의 조언 부탁드립니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
링크를 세부분으로 나누어 추출하려고 합니다.
다음과 같은 html 내용이 있을때,
**************************************************************
<a target=_blank href='http://www.naver.com'>네이버</a>
<area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
**************************************************************
1. <a 혹은 <area 태그 내용
(예: <a target=_blank href='http://www.naver.com'> )
2. 1내용중 href의 내용
(href내용은 큰따옴표 혹은 작은따옴표로 감싸지거나 그냥 링크만 있을수도..)
3. <a 혹은 <area 의 텍스트내용
(위 html의 첫째줄에서는 네이버, 둘째줄에서는 공백이 되겠네요.)
이 세 내용을 preg_match_all 함수와 정규식을 이용해 추출하고자 하는데,
정규식 작성이 잘 되지 않네요..
고수님들의 조언 부탁드립니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
댓글 2개
15년 전
내공이 부족해서 preg_match_all 은 못하겠네요.
<?
$s =<<<HTMLCODE
<a target=_blank href='http://www.naver.com'>네이버</a>
<area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
HTMLCODE;
preg_match("/(\<a[^\>]*\>)/i", $s, $match1);
preg_match("/href\=[\"\']?([^\"\'\s\>]+)/i", $match1[1], $match2);
preg_match("/\<a[^\>]*\>(.*)\<\/a/i", $s, $match3);
?>
<textarea rows=10 cols=100><?print_r($match1)?></textarea>
<textarea rows=10 cols=100><?print_r($match2)?></textarea>
<textarea rows=10 cols=100><?print_r($match3)?></textarea>
<?
$s =<<<HTMLCODE
<a target=_blank href='http://www.naver.com'>네이버</a>
<area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
HTMLCODE;
preg_match("/(\<a[^\>]*\>)/i", $s, $match1);
preg_match("/href\=[\"\']?([^\"\'\s\>]+)/i", $match1[1], $match2);
preg_match("/\<a[^\>]*\>(.*)\<\/a/i", $s, $match3);
?>
<textarea rows=10 cols=100><?print_r($match1)?></textarea>
<textarea rows=10 cols=100><?print_r($match2)?></textarea>
<textarea rows=10 cols=100><?print_r($match3)?></textarea>
JY소프트
14년 전
preg_match_all 로 만들어 봤습니다.
preg_match_all("/(<a[^>]*href=[\"']?([^>\"'\s]+)[\"']?[^>]*>)([^<]*)/i", $s, $out1);
echo "<xmp>";
print_r($out1);
echo "</xmp>";
Array
(
[0] => Array
(
[0] => <a target=_blank href='http://www.naver.com'>네이버
[1] => <area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
)
[1] => Array
(
[0] => <a target=_blank href='http://www.naver.com'>
[1] => <area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
)
[2] => Array
(
[0] => http://www.naver.com
[1] => http://www.daum.net
)
[3] => Array
(
[0] => 네이버
[1] =>
)
)
preg_match_all("/(<a[^>]*href=[\"']?([^>\"'\s]+)[\"']?[^>]*>)([^<]*)/i", $s, $out1);
echo "<xmp>";
print_r($out1);
echo "</xmp>";
Array
(
[0] => Array
(
[0] => <a target=_blank href='http://www.naver.com'>네이버
[1] => <area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
)
[1] => Array
(
[0] => <a target=_blank href='http://www.naver.com'>
[1] => <area shape="RECT" target="_blank" coords="10,10,135,60" href="http://www.daum.net" />
)
[2] => Array
(
[0] => http://www.naver.com
[1] => http://www.daum.net
)
[3] => Array
(
[0] => 네이버
[1] =>
)
)
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3030 | 14년 전 | 1170 | ||
| 3029 |
|
14년 전 | 1292 | |
| 3028 | 14년 전 | 1040 | ||
| 3027 | 14년 전 | 848 | ||
| 3026 | 14년 전 | 1031 | ||
| 3025 |
마케팅메지션
|
14년 전 | 1152 | |
| 3024 | 14년 전 | 862 | ||
| 3023 | 14년 전 | 847 | ||
| 3022 |
|
14년 전 | 1221 | |
| 3021 | 14년 전 | 1015 | ||
| 3020 | 14년 전 | 906 | ||
| 3019 | 14년 전 | 1060 | ||
| 3018 | 14년 전 | 1227 | ||
| 3017 |
마케팅메지션
|
14년 전 | 933 | |
| 3016 |
|
14년 전 | 970 | |
| 3015 | 14년 전 | 665 | ||
| 3014 | 14년 전 | 882 | ||
| 3013 | 14년 전 | 1092 | ||
| 3012 | 14년 전 | 922 | ||
| 3011 | 14년 전 | 924 | ||
| 3010 | 14년 전 | 1146 | ||
| 3009 |
마케팅메지션
|
14년 전 | 1658 | |
| 3008 | 14년 전 | 580 | ||
| 3007 | 14년 전 | 1017 | ||
| 3006 |
마케팅메지션
|
14년 전 | 1000 | |
| 3005 |
마케팅메지션
|
14년 전 | 893 | |
| 3004 | 14년 전 | 873 | ||
| 3003 |
마케팅메지션
|
14년 전 | 989 | |
| 3002 | 14년 전 | 776 | ||
| 3001 | 14년 전 | 2005 | ||
| 3000 | 14년 전 | 771 | ||
| 2999 | 14년 전 | 1667 | ||
| 2998 | 14년 전 | 758 | ||
| 2997 |
|
14년 전 | 847 | |
| 2996 | 14년 전 | 933 | ||
| 2995 | 14년 전 | 890 | ||
| 2994 | 14년 전 | 1597 | ||
| 2993 |
마케팅메지션
|
14년 전 | 1002 | |
| 2992 |
마케팅메지션
|
14년 전 | 961 | |
| 2991 |
마케팅메지션
|
14년 전 | 1130 | |
| 2990 | 14년 전 | 972 | ||
| 2989 | 14년 전 | 791 | ||
| 2988 |
|
14년 전 | 935 | |
| 2987 | 14년 전 | 815 | ||
| 2986 | 14년 전 | 1033 | ||
| 2985 | 14년 전 | 576 | ||
| 2984 | 14년 전 | 955 | ||
| 2983 | 14년 전 | 964 | ||
| 2982 | 14년 전 | 910 | ||
| 2981 | 14년 전 | 833 | ||
| 2980 |
마케팅메지션
|
14년 전 | 1168 | |
| 2979 |
마케팅메지션
|
14년 전 | 901 | |
| 2978 |
|
14년 전 | 844 | |
| 2977 |
|
14년 전 | 875 | |
| 2976 | 14년 전 | 818 | ||
| 2975 | 14년 전 | 815 | ||
| 2974 | 14년 전 | 895 | ||
| 2973 | 14년 전 | 1286 | ||
| 2972 | 14년 전 | 667 | ||
| 2971 | 14년 전 | 730 | ||
| 2970 | 14년 전 | 896 | ||
| 2969 | 14년 전 | 911 | ||
| 2968 | 14년 전 | 771 | ||
| 2967 | 14년 전 | 1351 | ||
| 2966 | 14년 전 | 853 | ||
| 2965 |
|
14년 전 | 1083 | |
| 2964 | 14년 전 | 1472 | ||
| 2963 | 14년 전 | 957 | ||
| 2962 |
|
14년 전 | 976 | |
| 2961 |
|
14년 전 | 886 | |
| 2960 | 14년 전 | 837 | ||
| 2959 | 14년 전 | 1179 | ||
| 2958 | 14년 전 | 929 | ||
| 2957 |
|
14년 전 | 808 | |
| 2956 |
|
14년 전 | 1186 | |
| 2955 |
|
14년 전 | 2341 | |
| 2954 | 14년 전 | 929 | ||
| 2953 | 14년 전 | 1051 | ||
| 2952 |
senseme
|
14년 전 | 1183 | |
| 2951 |
뱌미3059
|
14년 전 | 903 | |
| 2950 |
|
14년 전 | 950 | |
| 2949 | 14년 전 | 996 | ||
| 2948 | 14년 전 | 869 | ||
| 2947 |
|
14년 전 | 957 | |
| 2946 |
개발조각사
|
14년 전 | 2447 | |
| 2945 |
개발조각사
|
14년 전 | 1758 | |
| 2944 |
개발조각사
|
14년 전 | 6044 | |
| 2943 |
개발조각사
|
14년 전 | 1293 | |
| 2942 |
개발조각사
|
14년 전 | 1568 | |
| 2941 |
개발조각사
|
14년 전 | 1929 | |
| 2940 |
개발조각사
|
14년 전 | 3656 | |
| 2939 |
개발조각사
|
14년 전 | 2988 | |
| 2938 |
개발조각사
|
14년 전 | 2063 | |
| 2937 |
개발조각사
|
14년 전 | 1570 | |
| 2936 |
개발조각사
|
14년 전 | 4015 | |
| 2935 | 14년 전 | 1096 | ||
| 2934 | 14년 전 | 876 | ||
| 2933 | 14년 전 | 1051 | ||
| 2932 | 14년 전 | 980 | ||
| 2931 | 14년 전 | 976 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기