2024年4月29日发(作者:)

$node['attributes'] = null;

$node['attributes'] = $atts;

unset( $atts );

}

return $nodes;

}

private function removeAttributes( $nodes )

{

# Remove unwanted attributes

foreach( $nodes as $node )

{

# Check if node has any attributes to be kept

$node_name = $node['name'];

$new_attributes = '';

if( is_array( $node['attributes'] ) )

{

foreach( $node['attributes'] as $attribute )

{

if( ( is_array( $this->allow ) && in_array( $attribute['name'], $this->allow ) ) || $this->isException( $node_name, $attribute['name'], $this->exceptions ) )

$new_attributes = $this->createAttributes( $new_attributes, $attribute['name'], $attribute['value'] );

}

}

$replacement = ( $new_attributes ) ? "<$node_name $new_attributes>" : "<$node_name>";

$this->str = preg_replace( '/'. reg_escape( $node['literal'] ) .'/', $replacement, $this->str );

}

}

private function isException( $element_name, $attribute_name, $exceptions )

{

if( array_key_exists($element_name, $this->exceptions) )

{

if( in_array( $attribute_name, $this->exceptions[$element_name] ) )

return true;

}

return false;

}

private function createAttributes( $new_attributes, $name, $value )

{

if( $new_attributes )

$new_attributes .= " ";

$new_attributes .= "$name="$value"";

return $new_attributes;

}

}

>