A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in PHP to remove all html tags except paragraph and italics tags
Q:

Write a program in PHP to remove all html tags except paragraph and italics tags

0

PHP strip_tags()

Write a program in PHP to remove all html tags except paragraph and italics tags

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution

The function strip_tags() does completely get rid of all HTML elements. If you just want to keep some elements (for example, some limited formatting functionalities with <b> and <i> and <br /> tags), you provide a list of allowed values in the second parameter for strip_tags().

Syntax

strip_tags(string,allow)

Here, the first parameter string specifies the string to check and the second parameter allowspecifies allowable tags. These tags will not be removed. The given example demonstrates how to remove all HTML tags except paragraph and italics tags -

<?php
$input = 'The term <i>Official Ireland</i> is commonly <br />' .
	'used in  <b>the Republic of Ireland</b> to denote<br />' .
	' the media, cultural and religious establishment. '.
	'<script>alert("Nice try!");</script>' .
	'<img src="/spam.jpg" />';
	
echo strip_tags($input, '<b><br><i>');
?>

Output of the above code

The term Official Ireland is commonly 
used in  the Republic of Ireland to denote
the media, cultural and religious establishment. alert("Nice try!");

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now