How can the issue of <br /> tags being displayed in the source text be resolved when passing the Javascript as part of the $data variable?

The issue of <br /> tags being displayed in the source text when passing Javascript as part of the $data variable can be resolved by using the htmlspecialchars() function in PHP to encode the special characters before outputting the data. This function will convert characters like <, >, ", ', and & into their respective HTML entities, preventing the <br /> tags from being interpreted as HTML tags.

$data = &quot;&lt;script&gt;alert(&#039;Hello&#039;);&lt;/script&gt;&lt;br /&gt;World&quot;;
echo htmlspecialchars($data);