Method 1:
Directly take out the mark you want to take out
Copy the code The code is as follows:
//Remove the br tag
function strip($str)
{
$str=str_replace("
","",$str) ;
//$str=htmlspecialchars($str);
return strip_tags($str);
}
?>
Method 2.
There is a strip_tags function in PHP that can easily remove HTML tags.
echo strip_tags(“Hello
World”); // Remove HTML, XML and PHP tags.
Non-standard HTML codes can also be removed correctly:
echo strip_tags(“
”>cftea”); //Output cftea
in PHP You can use the strip_tags function to remove HTML tags, see the following example:
Copy the code The code is as follows:
$str = 'www
dreamdu
.com';
echo(htmlspecialchars($str)."
");
echo(strip_tags($str));
?>
方法3.
strtr() 函数转换字符串中特定的字符。
语法
strtr(string,from,to)
或者
strtr(string,array)
参数 |
描述 |
string1 |
必需。规定要转换的字符串。 |
from |
必需(除非使用数组)。规定要改变的字符。 |
to |
必需(除非使用数组)。规定要改变为的字符。 |
array |
必需(除非使用 from 和 to)。一个数组,其中的键是原始字符,值是目标字符。 |
Example 1:
Copy code The code is as follows:
echo strtr("Hilla Warld","ia","eo");
?>
Example 2:
Copy code The code is as follows:
$arr = array("Hello" => "Hi", "world" = > "earth");
echo strtr("Hello world",$arr);
?>
http://www.bkjia.com/PHPjc/327988.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327988.htmlTechArticleMethod 1: Directly remove the tag you want to remove. Copy the code. The code is as follows: ?php //Remove the br tag function strip ($str) { $str=str_replace("br","",$str); //$str=htmlspecialchars($str);...