Jump to content

Weirdness with a POST array and newlines.


awpti

Recommended Posts

So, here's the sample code:

 

It assumes no string is longer than 3 characters for the ord() function at the end.

 

<form method="post" action="test.php">
<textarea name="test"></textarea><br />
<input type="submit" name="testing" value="what the f!" />

<?php

$res = explode("\n", $_POST['test']);

foreach($res as $val)
{
       $fix[] = str_replace("\n", '', $val);
}

echo '<pre>';
var_dump($fix);
echo '</pre><br />';

echo 'Ordinal Value of last char: '.ord($fix[4]{3});

 

Weird thing?

 

You'll notice that the var_dump() shows each array entry as having a newline character except for the last one. If you echo the ordinal value of that extraneous character, it comes back as: 0 (0 == NULL)

 

My question:

 

What the HELL? Why is this kicking back as a newline character when ord() clearly shows it's null? It shouldn't even display, let alone have an ordinal value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.