보안과 관련이있는 경우, 즉 데이터를 항상 안전하게 표시 할 수 있는지 확인하려면 서버 측에서 수행해야합니다.
<br>
태그를 제외하고는 HTML 인코딩만으로 원하는 작업을 수행 할 수 있습니다.
$encoded_text = htmlentities($input_text);
// replace the encoded <br>'s with the original <br>'s
$final_text = str_replace(htmlentities("<br>"), "<br>", $encoded_text);
또 다른 방법으로 시도하는이 동작을 얻기 위해 여전히 htmlentities
이 자리로 <br>
태그를 대체하는 것입니다 사용
아마 가장 좋은 방법은 htmlentities을 사용하고 <br>
의 뒷면을 가지고하는 것입니다 htmlentities
을 실행 한 다음 다시 바꿉니다.
$br_placeholder = "XX_BR_PLACEHOLDER_XX";
$text_with_placeholders = str_replace("<br>", $br_placeholder, $input_text);
$text_with_htmlentities = htmlentities($text_with_placeholders);
$final_text = str_replace($br_placeholder, "<br>", $text_with_htmlentities);
지금까지 시도한 내용은 무엇인가요? 어떤 구체적인 문제가 있었습니까? 그리고 "태그"문자는 무엇입니까? – hakre
나는 htmlentities를 사용하여
을 다시 사용하는 @orip 첫 번째 방법을 사용했습니다. 나를 위해 잘 일했다! – cbr0wn