Jump to content

PHP taking spaces and turning to _'s


makeshift_theory

Recommended Posts

Hello guys and gals,

I am having a wierd problem I have never encountered before.  My forms are being dynamically created from a class and the turn out of that form is this:
[code]<center><form action="/admin/select_server.php" method="POST">
<input type="submit" name="viewnew" value="View Pending" class="button">
<br><br><input type="submit" name="Library" value="Library Server" class="button">
<br><br><input type="submit" name="Leads Library" value="Leads Library Server" class="button"><br><br><input type="submit" name="addnew" value="Add New Server" class="button"></form></center>[/code]
...as you can the name field is Leads Library with no spaces however when I run this code:
[code] if($_SERVER['REQUEST_METHOD']=='POST')
{
extract($_POST);
foreach($_POST as $k => $P)
echo $k;
}[/code]
... the key turns into Leads_Library..why is that?
Link to comment
https://forums.phpfreaks.com/topic/30230-php-taking-spaces-and-turning-to-_s/
Share on other sites

Althought I couldn't find a specific reference in the manual, I believe PHP will convert any characterin a form name that is illegal in a PHP variable name to an underscore. This is because a form name can potentionally become a PHP variable name. Since you can't have a space in a PHP variable name, it is replaced with an underscore. The manual does explicitly mention replacing a period in a form name with an underscore.

Ken

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.