/    Sign up×
Community /Pin to ProfileBookmark

Array Key Value problem

I’ve discovered that when you do something like:

[CODE]
MyArray[‘My Key.Thing’] = 37;
[/CODE]

the key value actually gets modified and becomes “My_Key_Thing”. That is, it translates certain characters into underscores. In particular it translates spaces and decimal points. Maybe it also translates other characters.

Is there a way to tell it to NOT do that translation?

Or, if that’s not possible, is there a function I can call that will do the same kind of translation so that I can produce a “proper” string myself for the key?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@RogerInHawaiiauthorJun 30.2007 — Actually, the problem actually only arises when the name of some form control ends up in the $_POST array. For example, if I have a control named "My Control" and the form gets submitted then the entry in the $_POST array actually gets a key value of "My_Control" instead of "My Control".

The solution MAY seem to be to simply not use spaces or decimal points in form controls. Howevere, I have a situation where some of my controls are dynamically generated and the names of those controls are a composite of the control type (e.g. "DeleteButton") and a file name, such as the name of the file that the button is intended to delete. Since I dont have control over what the name of the fie might be, and it may contain space characters and most likely will contain a decimal point, I've got a problem.

Any suggestions?
Copy linkTweet thisAlerts:
@bluestarsJun 30.2007 — Do it differently. ?

I'd have a hidden input called "DeleteButtonFile", and its value would contain the filename.

It may be possible to prevent that conversion, but I don't know how. I'd just avoid the whole thing.
Copy linkTweet thisAlerts:
@MrCoderJun 30.2007 — What are you trying to do?

There has to be a better way of doing it that how you currently are.
×

Success!

Help @RogerInHawaii spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...