Strip all text inside a tag although it has spaces in side the tag

[code]<?php
$string1=‘Text outside a tag ’;
$string2=‘Text outside a tag < text inside a tag>’;

$strip_tags1=strip_tags($string1)
$strip_tags2=strip_tags($string2)
;
echo $strip_tags1;
echo $strip_tags2;
?>[/code]I have the code above.

The result1 of atrip_tags1 is below

Text outside a tagstrip_tags work fine in the result1…

The result2 of atrip_tags2 is below

Text outside a tag < text inside a tag>strip_tags does not work in the result2…

I guess that the difference between result1 and result2 is caused by the spaces just after the open tag "< "…
I like to stip all text inside a tag although it has spaces anywhere inside the tag.

Thank you very much…

If there is a space after the < then it isn’t a tag.

I agree with @felgall that a < with space afterwards is not a tag, it wouldn’t execute etc if you really want to try and get the example to work, the easiest example is to run the strings against str_replace() a couple of times with varying spaces and then it will work.

<?php

$string1='Text outside a tag <text     inside a tag>';

$string2='Text outside a tag <  text      inside a tag>';

$string2 = str_replace('<  ', '<', $string2);

$strip_tags1=strip_tags($string1);
$strip_tags2=strip_tags($string2);
echo $strip_tags1;
echo $strip_tags2;
?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.