Home > Article > Backend Development > Simple filtering of HTML tags in string_PHP tutorial
function deleteHtml( $scr )
{
$l = strlen( $scr );
for( $i=0; $i<$l; $i++ )
{
if( substr( $scr, $i, 1 ) == "<" )
{
// Current location
$ii = $i;
// Stop looping when $i is greater than the character length
while( substr( $scr, $i, 1 ) != ">" && $i < $l )
$i++;
// When reaching the end of the large string, reset $i to the starting position of '<' found
if ( $i == $l )
{
$i = $ii - 1;
// Indicates reaching the end of the string
$b = 1;
}
$i++;
}
// Only accept characters when the next character is not '<', otherwise $i--, start searching from this '<'
if ( substr( $scr, $i, 1 ) != '<' || $b == 1 )
$str = $str . substr( $scr, $i, 1 );
else
$i--;
}
return( $str );
}