{"id":2197,"date":"2013-02-07T04:32:59","date_gmt":"2013-02-07T04:32:59","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=2197"},"modified":"2013-02-07T04:32:59","modified_gmt":"2013-02-07T04:32:59","slug":"php-remove-html-how-to-remove-html-tags-from-string-using-php-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/php-remove-html-how-to-remove-html-tags-from-string-using-php-examples\/","title":{"rendered":"How To Remove HTML Tags From String Using PHP &#8211; Examples"},"content":{"rendered":"<p>When using PHP to process the server side\u00a0requirements\u00a0of data cleansing, it can be immensely helpful to know how to remove HTML Tags from the user input. If these html tags are not removed, then your application may break, depending upon it&#8217;s architecture. So assuming that you do not want user to allow user to input HTML, what would you do if someone does enter HTML in input? In this article, I am going to share a very easy way to use <em><strong>PHP to\u00a0<\/strong><strong>remove html tags from user input<\/strong><\/em>.<\/p>\n<p><!--more--><\/p>\n<h2>Examples on how to remove HTML Tags from String using PHP<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2197\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>In order to see how to remove html from input, let&#8217;s assume that we have custom text with HTML tags in it. Now we will see how to remove these html tags using an example.<\/p>\n<h3>Example: Remove\u00a0HTML\u00a0tags from string using PHP<\/h3>\n<pre class=\"lang:php decode:true\" title=\"Example\">&lt;?php \n$content = '&lt;h1&gt;Hi&lt;\/h1&gt;, How are you?';\n\necho strip_tags($content);\n\necho '&lt;p&gt;The above will produce the output \"Hi, How are you?\". The change that happens is that the h1 tags will be removed.&lt;\/p&gt;';\n?&gt;<\/pre>\n<p>To summarize, <strong>simply apply the function strip_tags over the content that you want to remove HTML tags from<\/strong>.<\/p>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2197\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to use <strong><em>PHP to\u00a0remove html tags<\/em><\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When using PHP to process the server side\u00a0requirements\u00a0of data cleansing, it can be immensely helpful to know how to remove HTML Tags from the user input. If these html tags are not removed, then your application may break, depending upon it&#8217;s architecture. So assuming that you do not want user to allow user to input [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,13],"tags":[33],"class_list":["post-2197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-tips-and-tricks","category-tips-and-tricks","tag-php-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-zr","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=2197"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2197\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=2197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=2197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=2197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}