How to remove all html tags from string in PHP?

Member

emely

by emely , in category: PHP , a month ago

How to remove all html tags from string in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by katharina , a month ago

@emely As one of the approach you can use strip_tags function in PHP and take a look an example:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php

$text = '<p>text p</p>Text with no tag <div>div text</div>';

// text pText with no tag div text
echo strip_tags($text);

// <p>text p</p>Text with no tag div text
// If you want to keep specific tags
echo strip_tags($text, ['p']);