Remove text strings that start and end in "" and "" [closed]

0

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.

    
asked by E.R.A. 21.11.2016 в 15:26
source

2 answers

3

With the str_replace () function You can replace all symbols < and > by a space.

See Demo 1

$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 (?:<|&lt;)\/?([a-zA-Z]+) *[^<\/]*?(?:>|&gt;)

See demo 2

$string = '<abcd>hola<efgh><ijkl>bonito<mnop><qrs>mundo!<tuvw>';

echo preg_replace('/(?:<|&lt;)\/?([a-zA-Z]+) *[^<\/]*?(?:>|&gt;)/', ' ', $string);

// output: hola bonito mundo!
    
answered by 21.11.2016 в 15:37
2

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);
    
answered by 21.11.2016 в 16:26