Skip to content

Instantly share code, notes, and snippets.

@kamermans
Created January 13, 2017 03:18
Show Gist options
  • Save kamermans/73e4889e486b5222dbba464c156d8d7b to your computer and use it in GitHub Desktop.
Save kamermans/73e4889e486b5222dbba464c156d8d7b to your computer and use it in GitHub Desktop.
Test showing the preservation of LF line endings via base64 encoding
<?php
if ($_POST) {
header("content-type: application/json");
$data = $_POST;
if (isset($data["encoded_data"])) {
$data["decoded_data"] = base64_decode($data["encoded_data"]);
}
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit();
}
?>
<!doctype html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('#data').html("this is a test\nof the emergency\nbroadcasting system\nthis is only a test\n");
$('#form-id').submit(function (e){
// Encode textarea and save it the hidden field
$('#encoded_data').val(btoa($('#data').val()));
return true;
});
});
</script>
<form id="form-id" method="POST" target="_blank">
<textarea style="width: 30em; height: 10em;" name="data" id="data"></textarea><br>
<input type="hidden" name="encoded_data" id="encoded_data">
<button type="submit">Test!</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment