게시글 본문에서 특정태그 치환 문의
본문
게시글 본문에 <iframe src="http://test.com/"><iframe> 태그가 있습니다.
iframe 태그 시작과 끝을 div로 감싸주려고 하는데요
<div class="1">
<div class="2">
<iframe src="http://test.com/"><iframe>
</div>
</div>
본문에 iframe 태그가 들어있다면
자동으로 div로 감싸지게 치환시킬수 있을까요?
답변 3
$view['content'] = str_replace('<iframe>', '<div><iframe>', $view['content']);
$view['content'] = str_replace('</iframe>', '</iframe></div>', $view['content']);
echo $view['content'];
그냥 간단하게는 str_replace로 치환을 하시면 되지 않을까여? 두번햇 <ifr를 <div><ifr로 </ifr을 </ifr</div> 등으로요
<div id="myDiv">
<div class="1">
<div class="2">
<iframe src="http://test.com/"></iframe>
</div>
</div>
</div>
위와 같을 경우
문서 하단에
<script>
document.querySelector("#myDiv").innerHTML = document.querySelector("#myDiv").innerHTML.replaceAll("<iframe", "<div class='1'><div class='2'><iframe").replaceAll("</iframe>", "</iframe></div></div></iframe>");
</script>
답변을 작성하시기 전에 로그인 해주세요.