| 제목 | 정규식 질문.. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 글쓴이 | ㅅㅇ | 작성시각 | 2014/10/05 19:31:19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 제가작성한 php코드입니다.. <?php $ch = curl_init(); $url = 'http://job.incruit.com/jobdb_list/searchjob.asp?ct=14&ty=1&cd=3&page=1&sortfield=mod&sortorder=1&articlecount=30'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $text = curl_exec($ch); curl_close($ch); preg_match_all("/\d+\"> (.+) <\/a>|class=\"vcheck\"> (.+) </i", $text, $matches); print_r($matches); } ?> $url에 있는 http://job.incruit.com/jobdb_list/searchjob.asp?ct=14&ty=1&cd=3&page=1&sortfield=mod&sortorder=1&articlecount=30 에접속해서 회사이름과 제목을 정규식으로 가져올려고합니다.. 저런식으로 정규식을 작성했는데 print_r로 뽑아보니 
 빈공간 내용 빈공간 내용 빈공간 내용 이런식으로 출력이되는데 빈공간 없이 company 0~29 subject 0~29 차례대로 쭉 뽑아올려면 어떻게해야될까요 ..ㅠㅠ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 다음글 | 테이블 출력 질문 드립니다. (3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 이전글 | HTMLPurifier 코드이그나이터용 헬퍼로 ifra... (2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
                                들국화
                                /
                                2014/10/06 11:12:57 /
                                추천
                                0
                             | 
| 
                                darkninja
                                /
                                2014/10/07 16:19:16 /
                                추천
                                0
                             top_company 와 condition_tit 이 한꾸러미에 들어있지 않아서 정규식만으로는 힘들겠네요! html 라이브러리를 사용하시던지 만드셔야 편해지겠습니다. 정규식을 제대로 사용하려면 구간의 시작과 끝이 확실해야 하더군요! 
   <td class="company">
    <dl>
     <dd class="scrap"><img src="http://img.incruit.com/common/icon/icon_scrap_no.gif" width="14" height="14" id="icon_scrap_nor_1410070032222" name="icon_scrap" title="클릭하면 스크랩됩니다" style="vertical-align:middle; margin-top:-1px;cursor:pointer " onclick="callScrapAdd('IncJob', '', '', '1410070032222', 'nor')" /></dd>
     <dd class="top_company"><a href="http://job.incruit.com/jobdb_info/jobpost.asp?job=1410070032222"> (주)지오매틱코리아 </a>
                  <p><a href="http://job.incruit.com/jobdb_list/searchjob.asp?ct=9&ty=1&cd=1" rel="nofollow"><a href="http://job.incruit.com/jobdb_list/searchjob.asp?ct=31&ty=1&cd=1" rel="nofollow">우수기업</a></a></p>
     </dd>
    </dl>
   </td>
   <td>
    <ul class="jobtitle">
     <li  class="condition_tit"><a href="http://job.incruit.com/jobdb_info/jobpost.asp?job=1410070032222"  class="vcheck"> 병역특례 정보처리분야(보충역) 모집 </a>
     <span id="RecmdIcon"><img src="http://img.incruit.com/fe/sub_home_contents_job/img/bullet/icon_ucc03.gif" onmouseover="fnShowRecmd_Layer(this);return false;" onmouseout="fnHideRecmd_Layer(this);return false;"></span>
     </li>
     <li class="condition"><span class="terms">병역특례 | 회사내규</span>
     </li>
     <li class="new">
      <a href="http://job.incruit.com/jobdb_info/jobpost.asp?job=1410070032222"  onclick="return goCL(this,'18011','job','새창');" target="_blank" class="new" rel="nofollow"><span>새창</span></a>
     </li>
    </ul>
   </td> | 
| 
                                letsgolee
                                /
                                2014/10/07 21:46:28 /
                                추천
                                0
                             
                                <?php $ch = curl_init(); $url = 'http://job.incruit.com/jobdb_list/searchjob.asp?ct=14&ty=1&cd=3&page=1&sortfield=mod&sortorder=1&articlecount=30'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $text = curl_exec($ch); curl_close($ch); preg_match_all('/<dd class="top_company"><a [^>]+>([^<]+)<\/a>/i', $text, $matches); print_r($matches[1]); preg_match_all('/<li[ ]+class="condition_tit"><a[^>]+class="vcheck">([^<]+)(<img [^>]+>[ ]?)?(<img [^>]+>[ ]?)?<\/a>(\r)?\n/Ui', $text, $matches); print_r($matches[1]); ?> | 
| 
                                darkninja
                                /
                                2014/10/08 00:02:37 /
                                추천
                                0
                             
                                한글이 깨지는 경우 이렇게 호출하면 나오네요! $text = curl_exec_utf8($ch); //$text = curl_exec($ch); 아니면 이렇게 foreach ($matches[1] as $match) { echo iconv('EUC-KR', 'UTF-8', $match) . '<br>'; //echo $match . '<br>'; } http://stackoverflow.com/questions/2510868/php-convert-curl-exec-output-to-utf8 
/** The same as curl_exec except tries its best to convert the output to utf8 **/
function curl_exec_utf8($ch) {
    $data = curl_exec($ch);
    if (!is_string($data)) return $data;
    unset($charset);
    $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
    /* 1: HTTP Content-Type: header */
    preg_match( '@([\w/+]+)(;\s*charset=(\S+))?@i', $content_type, $matches );
    if ( isset( $matches[3] ) )
        $charset = $matches[3];
    /* 2: <meta> element in the page */
    if (!isset($charset)) {
        preg_match( '@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s*charset=([^\s"]+))?@i', $data, $matches );
        if ( isset( $matches[3] ) )
            $charset = $matches[3];
    }
    /* 3: <xml> element in the page */
    if (!isset($charset)) {
        preg_match( '@<\?xml.+encoding="([^\s"]+)@si', $data, $matches );
        if ( isset( $matches[1] ) )
            $charset = $matches[1];
    }
    /* 4: PHP's heuristic detection */
    if (!isset($charset)) {
        $encoding = mb_detect_encoding($data);
        if ($encoding)
            $charset = $encoding;
    }
    /* 5: Default for HTML */
    if (!isset($charset)) {
        if (strstr($content_type, "text/html") === 0)
            $charset = "ISO 8859-1";
    }
    /* Convert it if it is anything but UTF-8 */
    /* You can change "UTF-8"  to "UTF-8//IGNORE" to 
       ignore conversion errors and still output something reasonable */
    if (isset($charset) && strtoupper($charset) != "UTF-8")
        $data = iconv($charset, 'UTF-8', $data);
    return $data;
} | 
| 
                                ㅅㅇ
                                /
                                2014/10/09 05:44:54 /
                                추천
                                0
                             
                                감사합니다.
                             | 
클로즈 테그를 잘 캐치를 못하네요. .+에 <를 제외 시켜 주세요.