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";
}


So lazy that he can't even fill this column out.

© 2011 Suhas Tech. All rights reserved.
Proudly powered by Wordpress.