-1

While making a post feature with PHP , i realized that anyone can post their text with a tag also. For ex. <b> What's Up</b> or even <marquee>Look, moving</marquee> . When these types of data will be printed it would affect inside the post. Like <b> will make the post bold. There must a html tag or a way with PHP or Javascript to disable html inside a tag.

I'm well aware of strip_tags(), but this function strips the tags for ex. <b>blah blah</b> will be shown like blah blah but i want it to be shown <b> blah blah<b> but not the HTML effect it would cause.

Mihir Ujjainwal
  • 140
  • 2
  • 13
  • 1
    Possible duplicate of [HTML,PHP - Escape '<' and '>' symbols while echoing](http://stackoverflow.com/questions/10551116/html-php-escape-and-symbols-while-echoing) – xmojmr Feb 20 '15 at 20:28

2 Answers2

1

Use the strip-tags function. Something like:

<?php
strip_tags($content, '');
?>

The second parameter is for allowed tags.

To show the html but not run it use <pre> tags and CDATA:

<pre><![CDATA[
<b>Blah Blah</b>
]]></pre>

Unfortunately, this only works for XHTML and XML.

Another alternative. and probably the most viable, is <xmp>: http://jsfiddle.net/8yfghmL9/

Community
  • 1
  • 1
Peter Noble
  • 675
  • 10
  • 21
0

you can use

<?php
    echo strip_tags("Hello <b>world!</b>"); 
?>

this will strip the tags.. and give you pure text ...

Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93
Vishal Wadhawan
  • 1,085
  • 1
  • 9
  • 11