I'm working on an API endpoint that takes a POST request of form x-www-form-urlencoded. This mostly takes your typical set of string values, but in some cases, the values can be an array, which come in as duplicate keys, like so: name1=foo&amp;name2=bar&amp;arr=value1&amp;arr=value2&amp;arr=value3 I want to end up with the following: [   'name1' =&gt; 'foo',   'name2' =&gt; 'bar',   'arr' =&gt; [value1, value2, value3] ]  I've tried the following: filter_input_array(INPUT_POST, [   'name1' =&gt; FILTER_SANITIZE_STRING,   'name2' =&gt; FILTER_SANITIZE_STRING,   'arr' =&gt; [     'filter' =&gt; FILTER_DEFAULT,     'flags' =&gt; FILTER_FORCE_ARRAY   ] ]);  which gives me (     [name1] =&gt; foo     [name2] =&gt; bar     [arr] =&gt; Array         (             [0] =&gt; value3         )  )  and parse_str(file_get_contents(&quot;php://input&quot;), $params); which gives me: (     [name1] =&gt; foo     [name2] =&gt; bar     [arr] =&gt; value3 )  In both cases, the duplicate keys are overwritten, and I only get the last value. The top comment of the  function mentions that it does not parse duplicate keys in the CGI standard way, and presents a hefty function to manually parse out the fields. I'm wondering if there is a simpler way to do this, I simply want to get a sanitized array of all the input from the x-www-form-urlencoded POST call. Ideally just something like return filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); // also FILTER_SANITIZE_ARRAY for duplicate keys Is there any function that can accomplish this basic task, or do I really need to roll my own? If so, what's the best way to blanket sanitize an arbitrary user-input array coming in via this POST method, since I would wind up just using a function similar to that in the linked comment above?
100808
I have a PHP application that will on occasion have to handle URLs where more than one parameter in the URL will have the same name. Is there an easy way to retrieve all the values for a given key? PHP $_GET returns only the last value.   To make this concrete, my application is an OpenURL resolver, and may get URL parameters like this:  ctx_ver=Z39.88-2004 &amp;rft_id=info:oclcnum/1903126 &amp;rft_id=http://www.biodiversitylibrary.org/bibliography/4323 &amp;rft_val_fmt=info:ofi/fmt:kev:mtx:book &amp;rft.genre=book &amp;rft.btitle=At last: a Christmas in the West Indies.  &amp;rft.place=London, &amp;rft.pub=Macmillan and co., &amp;rft.aufirst=Charles &amp;rft.aulast=Kingsley &amp;rft.au=Kingsley, Charles, &amp;rft.pages=1-352 &amp;rft.tpages=352 &amp;rft.date=1871   (Yes, I know it's ugly, welcome to my world). Note that the key "rft_id" appears twice:   rft_id=info:oclcnum/1903126 rft_id=http://www.biodiversitylibrary.org/bibliography/4323   $_GET will return just http://www.biodiversitylibrary.org/bibliography/4323, the earlier value (info:oclcnum/1903126) having been overwritten.  I'd like to get access to both values. Is this possible in PHP? If not, any thoughts on how to handle this problem?
3020
How can I remove duplicate values from a multi-dimensional array in PHP?  Example array:  Array (     [0] =&gt; Array     (         [0] =&gt; abc         [1] =&gt; def     )      [1] =&gt; Array     (         [0] =&gt; ghi         [1] =&gt; jkl     )      [2] =&gt; Array     (         [0] =&gt; mno         [1] =&gt; pql     )      [3] =&gt; Array     (         [0] =&gt; abc         [1] =&gt; def     )      [4] =&gt; Array     (         [0] =&gt; ghi         [1] =&gt; jkl     )      [5] =&gt; Array     (         [0] =&gt; mno         [1] =&gt; pql     )  )
71972
In my post meta data I have the following 'key' for every post: "image_details" a typical value of which is an array such as:  a:3:{s:23:"info_window_bg_image_id";s:3:"128";s:12:"colour_start";s:7:"#000000";s:10:"colour_end";s:7:"#b7b7b7";}   In the above example - info_window_bg_image_id is equal to 128  Ideally I would like to find out how many posts have the image_details['info_window_bg_image_id'] set to 128 but I would settle to find out if any of the posts have that value set.  The only way that I can think to do it (with my limited knowledge) is something along the lines of:   Retrieve an array of every post in the database Foreach through the array using the ID's Use get_post_meta(ID, Key) to get the "image_details" key Check the value of the 'info_window_bg_image_id' element of the result to see if it matches the value.    This seems like it would be a heavy load because I would have to do this multiple times to check for other values.  Is there an easier way of doing this? Perhaps with a direct SQL query via the WP_Query class?  Just to reiterate my ideal would be to get a result that lets me know there are:   6 posts have post_meta image_details 'info_window_bg_image_id' set to 128 10 posts have post_meta image_details 'info_window_bg_image_id' set to 127 0 posts have post_meta image_details 'info_window_bg_image_id' set to 126   etc etc  But I would also be happy with a result that just says:  128 is used, 127 is used, 126 isn't used etc
114332
I have the problem, that PHP replaces all spaces with underscores in POST and GET variables. For example if I have the URL: http://localhost/proxy.php?user name=Max the browser will convert it to http://localhost/proxy.php?user%20name=Max. But if I give the $_GET parameters out, the key is not user name but user_name (note the underscore)! Is there any possibility to change this behaviour?
12435
How can I fetch a domain name from a URL String? Examples: +----------------------+------------+ | input                | output     | +----------------------+------------+ | www.google.com       | google     | | www.mail.yahoo.com   | mail.yahoo | | www.mail.yahoo.co.in | mail.yahoo | | www.abc.au.uk        | abc        | +----------------------+------------+  Related:
85935
I've got a multidimensional associative array which includes an elements like  $data["status"] $data["response"]["url"] $data["entry"]["0"]["text"]   I've got a strings like:  $string = 'data["status"]'; $string = 'data["response"]["url"]'; $string = 'data["entry"]["0"]["text"]';   How can I convert the strings into a variable to access the proper array element? This method will need to work across any array at any of the dimensions.
94609
I'm working at an app which would make a POST ajax request to a PHP script on my server. The script would query the database and return a row of records, as an array. (One array for each row, containing elements such as id, title, etc). I then want to use json_encode() to encode this array, and pass it back to the javascript which will use it to display the records.  1) How can I return the JSON encoded string to the javascript? 2) How will the javascript loop through the rows and access their fields?
9730
How can I remove duplicate values from an array in PHP?
60856
I have a string that looks like this:  "Name1=Value1;Name2=Value2;Name3=Value3"   Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this:  dict = {     "Name1": "Value1",     "Name2": "Value2",     "Name3": "Value3" }   I have looked through the modules available but can't seem to find anything that matches.    Thanks, I do know how to make the relevant code myself, but since such smallish solutions are usually mine-fields waiting to happen (ie. someone writes: Name1='Value1=2';) etc. then I usually prefer some pre-tested function.  I'll do it myself then.
122621
With all the URL-handling objects lying around in the standard Cocoa libraries (NSURL, NSMutableURL, NSMutableURLRequest, etc), I know I must be overlooking an easy way to programmatically compose a GET request.  Currently I'm manually appending "?" followed by name value pairs joined by "&amp;", but all of my name and value pairs need to be manually encoded so NSMutableURLRequest doesn't fail entirely when it tries to connect to the URL.  This feels like something I should be able to use a pre-baked API for.... is there anything out of the box to append an NSDictionary of query parameters to an NSURL? Is there another way I should approach this?
53730
I decided that I'll learn python tonight :) I know C pretty well (wrote an OS in it) so I'm not a noob in programming so everything in python seems pretty easy, but I don't know how to solve this problem : let's say I have this address:    Now how can I create two strings from this, one containing the "base" name of the server, so in this example it would be   and another containing the thing without the last filename, so in this example it would be   . Also I of course know the possibility to just find the 3rd and last slash respectively but maybe you know a better way :] Also it would be cool to have the trailing slash in both cases but I don't care since it can be added easily. So anyone has a good, fast, effective solution for this? Or is there only "my" solution, finding the slashes?  Thanks!
22775
Is there a library or acceptable method for sanitizing the input to an html page?  In this case I have a form with just a name, phone number, and email address.    Code must be C#.  For example:  "&lt;script src='bobs.js'&gt;John Doe&lt;/script&gt;" should become "John Doe"
96971
What is the Java equivalent of PHP's $_POST? After searching the web for an hour, I'm still nowhere closer.
103558
Is there an inbuilt PHP function to replace multiple values inside a string with an array that dictates exactly what is replaced with what?  For example:  $searchreplace_array = Array('blah' =&gt; 'bleh', 'blarh' =&gt; 'blerh'); $string = 'blah blarh bleh bleh blarh';   And the resulting would be: 'bleh blerh bleh bleh blerh'.
33014
I have the string which that encoded in .  How do I decode this in php?  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum felis = pede, vestibulum et, ullamcorper in, ultrices eget, metus. Suspendisse in n= ulla. Sed justo. Donec dapibus auctor neque. Pellentesque faucibus ante nec=  metus. Vivamus feugiat, velit rhoncus semper suscipit, libero augue venena= tis leo, nec ornare nulla elit eget diam. Nullam sollicitudin.
11190
When building console applications that take parameters, you can use the arguments passed to Main(string[] args).   In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands get more complicated, the parsing can get pretty ugly.    So I'm interested in:   Libraries that you use Patterns that you use   Assume the commands always adhere to common standards such as .
82950
I'm in the process of moving an application from PHP to Java and there is heavy use of regular expressions in the code.  I've run across something in PHP that doesn't seem to have a java equivalent:  preg_replace_callback()   For every match in the regex, it calls a function that is passed the match text as a parameter.  As an example usage:  $articleText = preg_replace_callback("/\[thumb(\d+)\]/",'thumbReplace', $articleText); # ... function thumbReplace($matches) {    global $photos;    return "&lt;img src=\"thumbs/" . $photos[$matches[1]] . "\"&gt;"; }   What would be the ideal way to do this in Java?