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
How to Get Count of Rows in MySQL Table Using PHP
How to Get Protected Property of Object in PHP
Force File Download With PHP Using Header()
Why Is MySQLi Giving a "Commands Out of Sync" Error
Full Secure Image Upload Script
Reference: Comparing PHP'S Print and Echo
What Is Thread Safe or Non-Thread Safe in PHP
PHP Multi-Dimensional Array Remove Duplicate
PHP Mail Not Working For Some Reason
PHP Function to Make Slug (Url String)
Is Closing the MySQL Connection Important
How Create an Array from the Output of an Array Printed With Print_R
Get All Permutations of a PHP Array
Nginx Serves .PHP Files as Downloads, Instead of Executing Them
How Do PHP Sessions Work? (Not "How Are They Used")