Is there a function in php to do a regex replace kind of action on all entries of an array?
I have an array that contains lots of html tags with text in them and I want to remove the tags.
So basically I'm converting this:
$m = [
"<div>first string </div>",
"<table>
<tr>
<td style='color:red'>
second string
</td>
</tr>
</table>",
"<a href='/'>
<B>third string</B><br/>
</a>",
];
to this:
$m = [
"first string",
"second string",
"third string"
]
The regex that (hopefully) matches everything I want to remove, looks like this:
/<.+>/sU
The question is just how I should use it now? (My array actually has more than 50 entries and in every entry there can be like 10 matches, so using preg_replace is probably not the way to go, or is it?)
Definition and Usage. The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter.
Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With