Remove All HTML Tags from PHP String

Remove all html tags from php string

use strip_tags

$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text); //output Test paragraph. Other text

<?php echo substr(strip_tags($row_get_Business['business_description']),0,110) . "..."; ?>

How to remove certain html tags in php strings

If you want to remove tags from a string in PHP (in this case, $str = "<b>England</b> is lovely";), you can use strip_tags($str); and it will return England is lovely
There is another parameter that you can add that doesn't remove certain tags, for example if $str = "<b>England</b> is my <div>city</div>"; and you type strip_tags($str, "<b>");, you will get <b>England</b> is my city.
Hope I helped!

How can I remove all HTML tags from a PHP string?

Well its ugly but works on this example

<?php
function translate($m) {
if(isset($m[1]) && $m[1] != "") {
$m[0] = str_replace($m[1], "", $m[0]);
return strip_tags($m[1]).$m[0];
}else {
return strip_tags($m[0]);
}
}

$re = "/(.*)`.*`|\n((?<![[:space:]]{4})(.*)\n)/m";
$string = "this is a `<a href='#'>link</a>`

<p>and this is a test</p>

Also this is another test.";
$string = $string.$string.$string.$string;
echo preg_replace_callback($re, "translate", $string);
?>

Output:

this is a `<a href='#'>link</a>`

<p>and this is a test</p>

Also this is another test.this is a `<a href='#'>link</a>`

<p>and this is a test</p>

Also this is another test.this is a `<a href='#'>link</a>`

<p>and this is a test</p>

Also this is another test.this is a `<a href='#'>link</a>`

<p>and this is a test</p>

Also this is another test.

How can I remove all html tags from an array?

No need for a regex here, just use strip_tags() to get rid of all html tags and then simply trim() the output, e.g.

$newArray = array_map(function($v){
return trim(strip_tags($v));
}, $m);


Related Topics



Leave a reply



Submit