awpti Posted April 29, 2009 Share Posted April 29, 2009 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. Link to comment https://forums.phpfreaks.com/topic/156056-weirdness-with-a-post-array-and-newlines/ Share on other sites More sharing options...
Mchl Posted April 29, 2009 Share Posted April 29, 2009 I guess you're running Windows. In windows newline mark is composed of two bytes: \r\n You're only removing \n. $fix[] = str_replace(array("\n","\r"), '', $val); Link to comment https://forums.phpfreaks.com/topic/156056-weirdness-with-a-post-array-and-newlines/#findComment-821632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.