This article introduces three methods of using php to delete html tags. Friends in need can refer to them.
Method 1, directly take out the desired mark. PHP functions used: str_replace, htmlspecialchars, strip_tags. <?php //取出br标记 function strip($str) { $str=str_replace("<br>","",$str); //$str=htmlspecialchars($str); return strip_tags($str); } ?> Copy after login 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 code can also be correctly removed: echo strip_tags(“">cftea”); //Output cftea Use strip_tags function to remove HTML tags. <?php $str = ‘www<p>dreamdu</p>.com'; echo(htmlspecialchars($str).”<br>”); echo(strip_tags($str)); ?> Copy after login Method 3, strtr function converts specific characters in the string. grammar strtr(string,from,to) or strtr(string,array) Parameter Description string1 required. Specifies the string to be converted. from Required (unless using an array). Specifies the character to be changed. to Required (unless using an array). Specifies the character to change to. array Required (unless from and to are used). An array where the keys are the original characters and the values are the target characters. Example 1: <?php echo strtr("Hilla Warld","ia","eo"); ?> Copy after login Example 2: <?php $arr = array("Hello" => "Hi", "world" => "earth"); echo strtr("Hello world",$arr); ?> Copy after login |