Jump to content
Larry Ullman's Book Forums

$_Post Character Coding


Recommended Posts

PHP Version 7.0.14 System Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux Build Date Dec 13 2016 07:47:37

BROWSER:

Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36stdClass Object ( [browser_name_regex] => ~^mozilla/5\.0 \(.*windows nt 10\.0.*\) applewebkit/.* \(khtml.* like gecko\) chrome/55\..*safari/.*$~ [browser_name_pattern] => Mozilla/5.0 (*Windows NT 10.0*) AppleWebKit/* (KHTML* like Gecko) Chrome/55.*Safari/* [parent] => Chrome 55.0 [platform] => Win10 [comment] => Chrome 55.0 [browser] => Chrome [version] => 55.0 [device_type] => Desktop [ismobiledevice] => [istablet] => )

 

Dear all

 

Firstly, great to see your photo on the website, Larry (it's been some while since I've been on the forum!) - I'm still using your great book PHP6 and MYSQL5 which is still incredibly helpful!!

 

Here is an issue that I haven't seen before - the POST method changing a full stop (period in US parlance) into an underscore:  This is a little quick program I've done for demonstration purposes:...

 

 <?php

 
if(isset($_POST))
{
foreach($_POST AS $key => $value)
{
echo 'ID is:....:' . $key . '..........Comment is:..:' . $value . '<br /><br />';
}
 
}
echo' <form action="test_post.php" method = "post" enctype="multipart/form-data">'; 
 
$a = "test_the_post_1.jpg";
$b = "test_the_post_2.jpg";
 
echo '
<textarea name = "' . $a . '" rows = "5" cols = "100">Comment here 1</textarea><br /><br />
<textarea name = "' . $b . '" rows = "5" cols = "100">Comment here 2</textarea><br /><br />
<input type = "submit" name = "submit" value = "UPDATE">
</form>';
 
?>
 
When I run test_post.php I get the following:
 
ID is:....:test_the_post_1_jpg..........Comment is:..:Comment here 1

 

ID is:....:test_the_post_2_jpg..........Comment is:..:Comment here 2

 

ID is:....:submit..........Comment is:..:UPDATE

 
You will notice that the post "test_the_post_1.jpg" has become test_the_post_1_jpg.
 
I have resolved this easily with str_replace() but don't really understand why it is occurring.
 
Keep up the great work, Larry.
Link to comment
Share on other sites

Hey Max! Thanks for the nice words. You cannot use periods (or full stops) in variable names in PHP. And although you're using these as _key_ names (for the $_POST array), PHP used to convert those to global variables, so I imagine that same mechanism for converting an invalid HTML ID/Name to a valid PHP variable name is still at play. 

 

Hope you're doing well!

Link to comment
Share on other sites

  • 3 weeks later...
 Share

×
×
  • Create New...