I was looking for how to make a string
remove all substring that starts and ends with "<" and ">" . Can someone guide me?
Edit: Yes, I was referring to labels with all their content.
I was looking for how to make a string
remove all substring that starts and ends with "<" and ">" . Can someone guide me?
Edit: Yes, I was referring to labels with all their content.
With the str_replace () function
You can replace all symbols <
and >
by a space.
$string = '<a> <span> <p>';
echo str_replace(['<', '>'], ' ', $string);
// output: a span p
To remove all strings that start with the% symbol <
and end >
you can use the function preg_replace () and with regex (?:<|<)\/?([a-zA-Z]+) *[^<\/]*?(?:>|>)
$string = '<abcd>hola<efgh><ijkl>bonito<mnop><qrs>mundo!<tuvw>';
echo preg_replace('/(?:<|<)\/?([a-zA-Z]+) *[^<\/]*?(?:>|>)/', ' ', $string);
// output: hola bonito mundo!
You could use the strip-tags function or a regular expression so that by means of the preg-replace function to replace these tags
$variable = "<adsd>Muy<efgh><xxx><qrs>Bien!<mmm>";
echo strip_tags($variable,'<\S>');
echo preg_replace('#<[^>]+>#', ' ', $variable);