How to Remove HTML Tags from a String in PHP

The strip_tags() function is used to remove HTML tags from a string. This function can be useful when you want to display text on a web page without HTML tags.

Syntax:

strip_tags($string, $allowed_tags);

Parameters:

  • string: Required. Specifies the string to remove HTML tags from
  • allowed_tags: Optional. Specifies which HTML tags are allowed. Default is all tags are allowed
$html = 'Welcome, <b>Peter</b><br />Profile';
$output = strip_tags($html, '<br>'); // 'Welcome, Peter<br />Profile'
$data = '<div class="content-wrapper">

    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                <h1>Dashboard</h1>
                </div>
            </div>
        </div>
    </section>

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card card-primary">
                        <div class="card-header">
                            <h4 class="card-title">Data List</h4>
                        </div>
                        <div class="card-body">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section> 

</div>';

echo strip_tags($data); //Output: "DashboardData List"

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close