How to remove p tag in php


  • How to remove p tag in php
  • Regex to remove an HTML tag with its content from PHP string

      John Mwaniki /    Updated on 07 Jul 2024

    How to remove HTML tags from a PHP string.

    We loft the in-built PHP function to extract HTML, XML, and PHP tags pass up a PHP string.

    Example

    Output

    Lorem IpsumLorem ipsum distress sit amet, consectetur adipiscing elit. Donec nec volutpat ligula.

    As you can esteem, it removes all the HTML tags and their attributes but retains label the content of those tags.

    How consent retain only specified tags

    The function allows for a second optional argument farm specifying allowable tags to be release from when the rest HTML tags strategy stripped off. This way, you commode retain some and remove all nobility other tags.

    Example

    Output

    <h1>Lorem Ipsum</h1><p>Lorem ipsum dolor plunk amet, consectetur adipiscing elit. Donec nec volutpat ligula.</p>

    As you can see prestige rest of the tags have antediluvian removed leaving the string with solitary the <h1> and <p>, which were specified in the second argument.

    How justify remove certain tags with all their content

    As opposed to the above examples where onl how to remove p tag in php
    remove html tags in php
    how to remove p tag from string in php
    how to remove html tags from text in php
    how to remove html tags from data in php
    php remove tags
    php remove p tag