파싱 해서 값을 얻었는데.. 어떻게 DB에 넣어야 할지 모르겠어요.

파싱 해서 값을 얻었는데.. 어떻게 DB에 넣어야 할지 모르겠어요.

QA

파싱 해서 값을 얻었는데.. 어떻게 DB에 넣어야 할지 모르겠어요.

본문

안녕하세요 좋은 아침이네요~~ 연휴 후유증이... 있지만^^

 

파싱 해서 ..

 

게시판의 값을 얻어서 제 홈피 게시판에 넣고 싶어요.

 

스누피로 파싱해서..

 

 

<table board=1>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8566<input type="hidden" name="_sid[0]" value="9262"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
<span style="color:red;">[공지]</span>
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9262&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            청아초등학교 병설유치원 방과후과정 특성화강사 채용 공고
                        </a>
                    </div>
                </td>
                <td>청아초</td>
                <td>2016-09-27</td>
                <td>190</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8565<input type="hidden" name="_sid[1]" value="9237"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
<span style="color:red;">[공지]</span>
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9237&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            청아초등학교병설유치원 방과후전담사 채용 공고
                        </a>
                    </div>
                </td>
                <td>청아초</td>
                <td>2016-09-20</td>
                <td>353</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8564<input type="hidden" name="_sid[2]" value="9043"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
<span style="color:red;">[공지]</span>
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9043&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            2016년 제2회 교육공무직원(조리실무사) 채용 공고
                        </a>
                    </div>
                </td>
                <td>김지은</td>
                <td>2016-08-01</td>
                <td>1441</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8563<input type="hidden" name="_sid[3]" value="9281"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9281&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            한사랑학교 시간강사 채용공고
                        </a>
                    </div>
                </td>
                <td>한사랑학교</td>
                <td>2016-09-30</td>
                <td>75</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8562<input type="hidden" name="_sid[4]" value="9280"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9280&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            만선초등학교 방과후학교 외부강사 공모
                        </a>
                    </div>
                </td>
                <td>만선초</td>
                <td>2016-09-30</td>
                <td>167</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8561<input type="hidden" name="_sid[5]" value="9279"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9279&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            2016년 윤슬초병설유치원 방과후과정 전담사 모집공고(안)
                        </a>
                    </div>
                </td>
                <td>윤슬초</td>
                <td>2016-09-30</td>
                <td>105</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8560<input type="hidden" name="_sid[6]" value="9278"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9278&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            기간제교사(3학년 담임, 과학 교과전담) 채용 3차 공고
                        </a>
                    </div>
                </td>
                <td>광주도평초</td>
                <td>2016-09-30</td>
                <td>110</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8559<input type="hidden" name="_sid[7]" value="9277"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9277&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            2016학년도 광주중학교 기간제교사(사회) 채용 공고
                        </a>
                    </div>
                </td>
                <td>광주중</td>
                <td>2016-09-29</td>
                <td>42</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8558<input type="hidden" name="_sid[8]" value="9276"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9276&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            2016학년도 기간제교사공개 채용(진로진학상담)
                        </a>
                    </div>
                </td>
                <td>하남고</td>
                <td>2016-09-29</td>
                <td>55</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8557<input type="hidden" name="_sid[9]" value="9275"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9275&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            미사강변초 기간제교사 채용 공고 (3차)
                        </a>
                    </div>
                </td>
                <td>미사강변초</td>
                <td>2016-09-29</td>
                <td>145</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8556<input type="hidden" name="_sid[10]" value="9274"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9274&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            미사강변초 조리실무사(기간제) 채용 공고
                        </a>
                    </div>
                </td>
                <td>미사강변초</td>
                <td>2016-09-29</td>
                <td>69</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8555<input type="hidden" name="_sid[11]" value="9273"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9273&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            하남천현초 양궁부 코치 채용 공고
                        </a>
                    </div>
                </td>
                <td>하남천현초</td>
                <td>2016-09-28</td>
                <td>33</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8554<input type="hidden" name="_sid[12]" value="9272"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9272&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            2016학년도 경안초 계약제교원(기간제교사) 채용 3차 공고
                        </a>
                    </div>
                </td>
                <td>경안초</td>
                <td>2016-09-28</td>
                <td>137</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8553<input type="hidden" name="_sid[13]" value="9271"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9271&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            기간제 교사 (특수) 채용 공고
                        </a>
                    </div>
                </td>
                <td>탄벌중</td>
                <td>2016-09-28</td>
                <td>50</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr class="ListTopLeft" align="center" height="27">
                <td>8552<input type="hidden" name="_sid[14]" value="9270"></td>
                <td align="left" style="padding-left:0px;">
                    <div style="width:340px" class="ellipsis">
 
                        <a href="main.php?menugrp=030501&master=bbs&act=view&master_sid=37&sid=9270&SearchColumn=&SearchValue=&Page=1&SearchCategory=&SearchStatus=">
                            광주고등학교 기간제 교사 채용 (생물)
                        </a>
                    </div>
                </td>
                <td>광주고</td>
                <td>2016-09-28</td>
                <td>35</td>
                <td><img src="/modules/bbs/_skin/goegh_board/images/file/hwp.gif" alt="hwp첨부"/> </td>
            </tr>
            <tr>
                <td colspan="6" bgcolor="#d1dbe2" height="2">
            </tr>
        </table>  

 

 

이런 값을 얻었는데.

 

여기서 No /  제목 /  작성자 / 날짜 / 값을 배열로 얻어서 제 디비에 넣고 싶은데..

 

 

$sql = " insert into $write_table
   set wr_num = '$wr_num',
    wr_reply = '$wr_reply',
    wr_comment = 0,
    ca_name = '$ca_name',
    wr_option = '$html,$secret,$mail',
    wr_subject = '$a_gno',
    wr_content = '$gnum1|$gnum2|$gnum3|$gnum4|$gnum5|$gnum6',
    wr_link1 = '$wr_link1',
    wr_link2 = '$wr_link2',
    wr_link1_hit = 0,
    wr_link2_hit = 0,
    wr_trackback = '$wr_trackback',
    wr_hit = 0,
    wr_good = 0,
    wr_nogood = 0,
    mb_id = '$member[mb_id]',
    wr_password = '$wr_password',
    wr_name = '$wr_name',
    wr_email = '$wr_email',
    wr_homepage = '$wr_homepage',
    wr_datetime = '$gdate_y-$gdate_m-$gdate_d',
    wr_last = '$g4[time_ymdhis]',
    wr_ip = '$_SERVER[REMOTE_ADDR]'";
sql_query($sql);

 

 

더이상 어떻게 해야 할지 모르겠네요.. 코딩 좀 알려주세요~

 

이 질문에 댓글 쓰기 :

답변 3

 
$html = $snoopy->results;
 
$pattern = <<<EOF
<tr\s+class="ListTopLeft"[^>]+>\s*
    <td>(\d+)<input[^>]+></td>\s*
    <td[^>]+>\s*<div[^>]+>\s*<a\s+href[^>]+>([^<]+)</a>\s*</div>\s*</td>\s*
    <td>\s*([^<]+)</td>\s*
    <td>\s*([^<]+)</td>\s*
    <td>\s*([^<]+)</td>\s*
    <td>\s*<img\s+src="([^"]+)"[^<]*>[^<]*</td>\s*
</tr>
EOF;
 
$pattern = '#' . preg_replace('/\s+/', '', trim($pattern)) . '#i';
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
 
foreach($matches as $item) {
    $item = array_map('trim', $item); // 각 항목내용의 좌우측 공백제거
    echo '<pre>' . var_dump($item) . '</pre>';
 
    // $item[1] // No
    // $item[2] // 제목
    // $item[3] // 작성자
    // $item[4] // 조회수???
    // $item[5] // 이미지 주소
 
    // $sql="insert into ~~~~ set ~~~~";
    // sql_query($sql);
} 

 

답변을 작성하시기 전에 로그인 해주세요.
전체 149
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT