채택완료

정규식 잘하시닌분조와주세요

2014-12-30 (화) 17:25:53 4,195

네이버 파싱해서 보드에넣고있는데요

파싱은됫는데 파싱된 데이터를 입력하려고보니가 안되서질문드림니다

아래소스는 파싱된 페이지에서 소스보기했을때 저렇게나오는데요 

입력을하려고하니가 앞에 첫줄(빨간색부분)만 들어가고 나머지는 

안들어가지네요

​

 

이거는 파싱할때 쓴소스임니다

 

Copy
​​$pattern = "/http:\/\/(postfiles).*\.(jpg).?type=w1/Ui";$contents = file_get_contents($url);preg_match_all($pattern, $contents, $match);foreach($match[0] as $key => $img) {$val = substr($img, 0, -1);$img2 = '<img src="'.$img.'">'."<br>";    //echo 햇을경우 잘보임...... $newpost[wr_content] = "$img2";           // 보드에 입력할때 첫줄만들가짐,..
​​
|

답변 6개 / 댓글 5개

채택된 답변
+20 포인트
Copy
$pattern = "/http:\/\/(postfiles).*\.(jpg).?type=w1/Ui"; $contents = file_get_contents($url); preg_match_all($pattern, $contents, $match); foreach($match[0] as $key => $img) { $val = substr($img, 0, -1); $img2 = '<img src="'.$img.'">'."<br>";$newpost[wr_content] .= "$img2"; }$newpost[bo_table] = "free"; $newpost[wr_subject] = "$it_name"; $newpost[wr_link1] = "$url"; $newpost[mb_id] = 'admin'; $result = m3post($newpost);
 

$pattern = "/http:\/\/(postfiles).*\.(jpg).?type=w1/Ui"; 

$contents = file_get_contents($url); 
preg_match_all($pattern, $contents, $match); 
foreach($match[0] as $key => $img) { 
$val = substr($img, 0, -1); 
$img2 = '<img src="'.$img.'">'."<br>";

$newpost[wr_content] .= "$img2"; 
}
$newpost[bo_table] = "free"; 
$newpost[wr_subject] = "$it_name"; 

$newpost[wr_link1] = "$url"; 
$newpost[mb_id] = 'admin'; 
$result = m3post($newpost);  

답변에 대한 댓글 1개

이거때문에 8시간헤멧는데 ㅋㅋㅋㅋ. 감사함니다. 늙어서 해볼라니가 어지럽네여,ㅋㅋ

$pattern = '@<img src="http://postfiles.*\?type=w1">@';

$contents = file_get_contents($url);

preg_match($pattern, $contents, $match);

$newpost[wr_content] = $match[0]; 

같은상황이네요...

 

$pattern = "/http:\/\/(postfiles).*\.(jpg).?type=w1/Ui"; 

$contents = file_get_contents($url); 
preg_match_all($pattern, $contents, $match); 
foreach($match[0] as $key => $img) { 
$val = substr($img, 0, -1); 
$img2 = '<img src="'.$img.'">'."<br>"; 
}
$newpost[bo_table] = "free"; 
$newpost[wr_subject] = "$it_name"; 
$newpost[wr_content] = "$img2"; 
$newpost[wr_link1] = "$url"; 
$newpost[mb_id] = 'admin'; 
$result = m3post($newpost); 

?>  

 

혹시 저기 $img2를 $wr_1 부터 10까지 이미지1개씩 따로따로 불러올려면 foreach을어덯게 작성해야되는지요?

아니면 다른방법이라도....​

아래처럼 1개식잘라서 넣으면들어갈거같아서요

$newpost[wr_1] = "$img_1";

$newpost[wr_2] = "$mg_​2";

$newpost[wr_3] = "$img_​3";

$newpost[wr_4] = "$mg_​4";

$newpost[wr_5] = "$mg_​5";

맨앞에 빨간부분은 <img src="http://postfiles1.naver.net/122930_01.jpg?type=w1"><br>

입니다.​


<img src="http://postfiles1.naver.net/122930_01.jpg?type=w1"><br>

<img src="http://postfiles1.naver.net/122930_01.jpg?type=w1"><br>​

이렇게나오네요...​ 아래소느도한번봐주실래요 아래거를바궈보니 위에이미지를 다가져오는데

게시글이 이미지숫자만큼 작성됨니다 이미지가 10개면 게시글 10개작성됨니다.

 

현제입력부분...

$row = sql_fetch("select count(*) as cnt from {$write_table} where wr_link1 = '$wr_link1'"); 

if($row['cnt']) return false; 

아래거로했을때는 이미지를 전부다가져오나 게시글이 이미지숫자만큼 작성되서 올라가네요

 //$row = sql_fetch("select count(*) cnt from {$write_table} where wr_content = '$wr_content'"); 

 //if($row['cnt']) return false;  

답변에 대한 댓글 3개

$row = sql_fetch("select count(*) as cnt from {$write_table} where wr_link1 = '$wr_link1'");
if($row['cnt']) return false;
이건 입력과는 관계없어 보이구요.
foreach()문의 블럭이 insert 이후에 닫히는 모양이군요. insert 이전으로 닫는괄호(})를 옮기셔야 할겁니다.
$pattern = "/http:\/\/(postfiles).*\.(jpg).?type=w1/Ui";
$contents = file_get_contents($url);
preg_match_all($pattern, $contents, $match);
foreach($match[0] as $key => $img) {
$val = substr($img, 0, -1);
$img2 = '<img src="'.$img.'">'."<br>";

$newpost[bo_table] = "free";
$newpost[wr_subject] = "$it_name";
$newpost[wr_content] = "$img2";
$newpost[wr_content] .= "$img2";
$newpost[wr_link1] = "$url";
$newpost[mb_id] = 'admin';
$result = m3post($newpost);
}
?>
맨아래 닫히게해놧는데이리저리옴겨볼게요
foreach가 m3post(); 뒤에 닫기네요. newpost 가 시작되는줄 위로 올리시면 되겠네요
$newpost[wr_content] = "$img2";
이 라인은 지우시구요

해봤는데 똑같네요,ㅜ.ㅜ

답변에 대한 댓글 1개

맨앞의 빨간게 어떤부분이죠?

$newpost[wr_content] = "$img2";           // 보드에 입력할때 첫줄만들가짐,..

$newpost[wr_content] .= "$img2";

로 하셔야..하는게 아닐까요 

답변을 작성하려면 로그인이 필요합니다.