Encode string to match encoded form field name in PHP POST array -


the name of html checkbox form field this:

name = "some file name.pdf" 

the php post array looks (some characters replaced underscore):

array(  "some_file_name_pdf" => "on" ) 

is there php function can use convert filename string appears in post array? not interested in str_replace. want able this:

$myfilename = $obj->getfilename(); // returns "some file name.pdf" $result = isset($_post[some_encoding_function($myfilename)]); 

the some_encoding_function should take string "some file name.pdf" , return "some_file_name_pdf";

according the php documentation:

dots , spaces in variable names converted underscores.

this require trivial string substitution.
however, according a comment on page:

the full list of field-name characters php converts _ (underscore) following (not dot):
chr(32) ( ) (space)
chr(46) (.) (dot)
chr(91) ([) (open square bracket)
chr(128) - chr(159) (various)

if comment correct, should go function

function underscorify($s) {     return preg_replace('/[ \.\[\x80-\x9f]/', '_', $s); } 

note however, chr(128) - chr(159) ambiguous, not mentioned whether character-encoding-dependent or not.
may refer ascii characters Ÿ, may refer utf-8 control characters \u0080-\u009f, or may hardcoded check byte value b >= 128 && b <= 159.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -