How to fetch the new line / paragraph character “n” from a GET / POST request




Here’s a little code that I wrote to correctly fetch the newline character. By URL encoding “n” you get %OA which is not decoded back as a C style new line character “n”. So, we fetch the query string to manually decode it in the correct mechanism. This is a PHP example, the theory hold good for other languages as well.


function get_string_parameters($string) {
$result = array();
if( empty($string) || !is_string($string) ) return $result;
$string = str_replace('&', '&', $string);
$params_array = explode('&', $string);
foreach($params_array as $value) {
$tmp_array = explode('=', $value);
if( count($tmp_array) != 2) continue;
$result[$tmp_array[0]] = $tmp_array[1];
}
return $result;
}

$getstuff = get_string_parameters($_SERVER['QUERY_STRING']);
$paragraphs = explode("%OA", $getstuff['YOUR-GET-FIELD']); // edit here
$yourmessage = "";
foreach ($paragraphs as $paragraph)
{
$yourmessage = $yourmessage.urldecode($paragraph)."n";
}






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?