자신이 쓴 댓글 다른곳에서 사용 시 이미지 태그 preg_replace 해결방법

자신이 쓴 댓글 다른곳에서 사용 시 이미지 태그 preg_replace 해결방법

QA

자신이 쓴 댓글 다른곳에서 사용 시 이미지 태그 preg_replace 해결방법

본문

안녕하세요 선배님들!

자신이 쓴 댓글만 모아서 지금 만드는 중인데,

wr_is_comment로 댓글과 본인 조건을 넣어서 wr_content를 불러오는데 까지는 했습니다.

 

댓글 같은경우

최고에요

[https://test.com/data/editor/2301/ ~~~ . png] 이런식으로 표시가 되는데

 

자세히 보니 []안에 주소는 <a href=""> </a> 로 감싸져 있더라고요.

 

그래서 인지 따로 작업한 페이지에서는 [https://test.com/data/editor/2301/ ~~~ . png]를 단순히 텍스트로 불러와져서 생기는 문제 같습니다.

이미지를 한번 view_comment.php 에서처럼 <a href=""></a>로 감싸고 해야 적용이 가능할듯 한데, 방법을 도저히 모르겠습니다.

wr_content를 어떻게 불러서 처리해야 a태그 먹힌상태로 불러올 수 있을까요..?


    // 이미지
    $newcomment = preg_replace("/\[\<a\s*href\=\"(http|https|ftp)\:\/\/([^[:space:]]+)\.(gif|png|jpg|jpeg|bmp)\"\s*[^\>]*\>[^\s]*\<\/a\>\]/i", "<img id=\"img\" src=\"$1://$2.$3\" alt=\"\" class=\"img-fluid\">", $comment);
    // 동영상
    $newcomment = preg_replace("/\[\<a\s.*href\=\"(http|https|ftp|mms)\:\/\/([^[:space:]]+)\.(mp3|wma|wmv|asf|asx|mpg|mpeg)\".*\<\/a\>\]/i", "<script>doc_write(obj_movie('$1://$2.$3'));</script>", $comment);
    // 컨텐츠
    $newcomment = na_content($comment);

하루종일 해도 안풀려서 ㅜㅜ

귀중한 답변 기다리고 있겠습니다..

이 질문에 댓글 쓰기 :

답변 2

a 태그를 포함해야 한다면서

예시코드 에서는 a 태그를 제외하고 결과를 뽑으려는 형태같고

전체적인 상황설명도 부족한것 같습니다.

 

인풋, 아웃풋 각각 명확하게 예시 케이스를 하나 제시하는게 좋을것 같습니다.

 

예시코드로 input 에서 output 이 나오고 있는데

input 코드 추측이 잘못된 것인지 모르겠습니다.

 

input


<div>
    sdfgsdfg
    [<a href="http://test.com/data/editor/2301/1.png">http://test.com/data/editor/2301/1.png</a>]
    [<a href="https://test.com/data/editor/2301/2.gif">https://test.com/data/editor/2301/2.gif</a>]
    [<a href="ftp://test.com/data/editor/2301/3.jpg">ftp://test.com/data/editor/2301/3.jpg</a>]
    342qtarg
    [<a href="mms://test.com/data/editor/2301/4.mp3">mms://test.com/data/editor/2301/4.mp3</a>]
    [<a href="ftp://test.com/data/editor/2301/5.mpeg">ftp://test.com/data/editor/2301/5.mpeg</a>]
    dsfg65tjy
</div>

 

output-1


<div>
    sdfgsdfg
    <img id="img" src="http://test.com/data/editor/2301/1.png" alt="" class="img-fluid">
    <img id="img" src="https://test.com/data/editor/2301/2.gif" alt="" class="img-fluid">
    <img id="img" src="ftp://test.com/data/editor/2301/3.jpg" alt="" class="img-fluid">
    342qtarg
    [<a href="mms://test.com/data/editor/2301/4.mp3">mms://test.com/data/editor/2301/4.mp3</a>]
    [<a href="ftp://test.com/data/editor/2301/5.mpeg">ftp://test.com/data/editor/2301/5.mpeg</a>]
    dsfg65tjy
</div>

 

output-2


<div>
    sdfgsdfg
    [<a href="http://test.com/data/editor/2301/1.png">http://test.com/data/editor/2301/1.png</a>]
    [<a href="https://test.com/data/editor/2301/2.gif">https://test.com/data/editor/2301/2.gif</a>]
    [<a href="ftp://test.com/data/editor/2301/3.jpg">ftp://test.com/data/editor/2301/3.jpg</a>]
    342qtarg
    <script>doc_write(obj_movie('mms://test.com/data/editor/2301/4.mp3'));</script>
    <script>doc_write(obj_movie('ftp://test.com/data/editor/2301/5.mpeg'));</script>
    dsfg65tjy
</div>
답변을 작성하시기 전에 로그인 해주세요.
전체 123,479 | RSS
QA 내용 검색

회원로그인

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