How can properly escaped content with html tag

For ex.

<?php
$data = '<div class="test"><label>Title</label><a href="#">Link</a><script type="text/javascript"> var i = "test";</script></div>';
echo $data;
?>

Envato Theme Check produce Warning
WARNING: Found echo $ in the file filename.php. Possible data validation issues found. All dynamic data must be correctly escaped for the context where it is rendered.

How can i solve this warning proper way.

echo wp_kses_post( $data );

2 Likes