문제

im trying to use Strip_tags and nl2br on the content which i echo out from the database. However, strip_tags doesnt work but nl2br does. What i want to do is to remove all the html or php tags inside the content if it is possible. By the way im using php 5.2.17 . Please help.

Output

Content:
<p><span style="color: #00ff00;">This is a new Page<br /><br />This is a new sentence</span></p>

Content

Content:<br />
                            <div class="view-content">

                                <?php echo 
                                strip_tags(htmlentities($current_page["content"])); ?>
                            </div>
도움이 되었습니까?

해결책

If you're using strip_tags you don't need htmlentites. You output is being converted to entites first and so you don't have any tags to strip. Change it to:

 <?php echo strip_tags($current_page["content"]); ?>

다른 팁

You should do:

echo htmlentities(strip_tags($current_page["content"]));

Since you were calling htmlentities first, the tags couldn't be recognized in the content because the < and > characters were replaced with &lt; and &gt;.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top