How can the width of a textarea be adjusted to accommodate a long string in PHP?

When dealing with long strings in a textarea in PHP, you can adjust the width of the textarea to accommodate the string by setting the 'cols' attribute to a suitable value based on the length of the string. This will ensure that the entire string is visible within the textarea without the need for horizontal scrolling.

<?php
$longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac elit ac metus vestibulum elementum.";
$cols = strlen($longString) + 10; // Adjust the number as needed for proper display
echo "<textarea cols='$cols'>$longString</textarea>";
?>