I have a verrrrrrrry long base64 encoded string which is displayed in a textarea. The problem is that this string doesn't have any spaces or carriage returns so it gets displayed on one line with a ugly horizontal scroll bar.
Can I add somehow carriage returns manually after base64_encode() and before output to the textarea, then remove these CR's after retrieving this string from the textarea (before decoding)?
You could use chunk_split
to split your string into chunks of a specific length, and then rejoin those chunks with the character or string you want:
$str = base64_encode($whatever);
echo '<textarea name="textarea">'
. chunk_split($str, 30, "\n") // put a newline every 30 characters
. '</textarea>';
As base64_decode
ignores whitespace, you don't need to do anything special once you retrieve the textarea value.
Certainly. White space is ignored:
<?php
echo base64_encode('Lorem Ipsump'); // TG9yZW0gSXBzdW1w
echo base64_decode('TG9 yZW0gS XBz dW1w'); // Lorem Ipsump
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With