How can the use of different HTML elements like input and textarea affect the process of copying text with line breaks to the clipboard in PHP?

When copying text with line breaks to the clipboard in PHP, using different HTML elements like input and textarea can affect the process. Input elements do not preserve line breaks, while textarea elements do. To ensure that line breaks are maintained when copying text to the clipboard, it is recommended to use textarea elements for multiline text inputs.

<?php
$text = "This is a text with
line breaks";
echo '<textarea id="copyText" style="display:none;">'.$text.'</textarea>';
echo '<button onclick="copyToClipboard()">Copy Text</button>';
?>

<script>
function copyToClipboard() {
  var copyText = document.getElementById("copyText");
  copyText.select();
  document.execCommand("copy");
  alert("Text copied to clipboard");
}
</script>