get

How to set and get fields in struct's method

扶醉桌前 提交于 2019-11-26 21:58:10
After creating a struct like this: type Foo struct { name string } func (f Foo) SetName(name string){ f.name=name } func (f Foo) GetName string (){ return f.name } How do I create a new instance of Foo and set and get the name? I tried the following: p:=new(Foo) p.SetName("Abc") name:=p.GetName() fmt.Println(name) Nothing gets printed, because name is empty. So how do I set and get a field inside a struct? Commentary (and working) example: package main import "fmt" type Foo struct { name string } // SetName receives a pointer to Foo so it can modify it. func (f *Foo) SetName(name string) { f

Javascript window.open pass values using POST

筅森魡賤 提交于 2019-11-26 21:57:54
I have a javascript function that uses window.open to call another page and returning the result. Here is the section of my code: var windowFeatures = "status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=1"; window.open ('http://www.domain.com/index.php?p=view.map&coords=' + encodeURIComponent(coords), 'JobWindow', windowFeatures); My problem now is that I am passing to much data for the GET to handle and I need to pass it using the POST method. How can I convert the code above to open the page using the POST method without implement forms all over the page (the

Get hwnd by process id c++

我的未来我决定 提交于 2019-11-26 21:38:51
问题 How can I get the HWND of application, if I know the process ID? Anyone could post a sample please? I'm using MSV C++ 2010. I found Process::MainWindowHandle but I don't know how to use it. 回答1: HWND g_HWND=NULL; BOOL CALLBACK EnumWindowsProcMy(HWND hwnd,LPARAM lParam) { DWORD lpdwProcessId; GetWindowThreadProcessId(hwnd,&lpdwProcessId); if(lpdwProcessId==lParam) { g_HWND=hwnd; return FALSE; } return TRUE; } EnumWindows(EnumWindowsProcMy,m_ProcessId); 回答2: You can use EnumWindows and

How to switch from POST to GET in PHP CURL

时光总嘲笑我的痴心妄想 提交于 2019-11-26 21:38:18
I have tried switching from a previous Post request to a Get request. Which assumes its a Get but eventually does a post. I tried the following in PHP : curl_setopt($curl_handle, CURLOPT_POSTFIELDS, null); curl_setopt($curl_handle, CURLOPT_POST, FALSE); curl_setopt($curl_handle, CURLOPT_HTTPGET, TRUE); What am I missing? Additional information: I already have a connection that's setup to do a POST request. That completes successfully but later on when I try to reuse the connection and switch back to GET using the setopts above it still ends up doing a POST internally with incomplete POST

Create a simple HTTP server with Java?

孤街浪徒 提交于 2019-11-26 21:35:26
What's the easiest way to create a simple HTTP server with Java? Are there any libraries in commons to facilitate this? I only need to respond to GET/POST , and I can't use an application server. What's the easiest way to accomplish this? Kris Use Jetty . Here's a tutorial for embedding Jetty . (Here's an outdated tutorial .) Jetty is pretty lightweight, but it does provide a servlet container, which may contradict your requirement against using an "application server". You can embed the Jetty server into your application. Jetty allows EITHER embedded OR servlet container options. This is how

Get last word from URL after a slash in PHP

一曲冷凌霜 提交于 2019-11-26 21:13:03
问题 I need to get the very last word from an URL. So for example I have the following URL: http://www.mydomainname.com/m/groups/view/test I need to get with PHP only "test", nothing else. I tried to use something like this: $words = explode(' ', $_SERVER['REQUEST_URI']); $showword = trim($words[count($words) - 1], '/'); echo $showword; It does not work for me. Can you help me please? Thank you so much!! 回答1: by using regex: preg_match("/[^\/]+$/", "http://www.mydomainname.com/m/groups/view/test",

Access GET directly from JavaScript?

走远了吗. 提交于 2019-11-26 20:47:08
I suppose I could use PHP to access $_GET variables from JavaScript: <script> var to = $_GET['to']; var from = $_GET['from']; </script> <script src="realScript" type="text/javascript"></script> But perhaps it's even simpler. Is there a way to do it directly from JS? Look at window.location.search It will contain a string like this: ?foo=1&bar=2 To get from that into an object, some splitting is all you need to do: var parts = window.location.search.substr(1).split("&"); var $_GET = {}; for (var i = 0; i < parts.length; i++) { var temp = parts[i].split("="); $_GET[decodeURIComponent(temp[0])] =

PHP - Get array value with a numeric index

淺唱寂寞╮ 提交于 2019-11-26 20:34:35
问题 I have an array like: $array = array('foo' => 'bar', 33 => 'bin', 'lorem' => 'ipsum'); echo native_function($array, 0); // bar echo native_function($array, 1); // bin echo native_function($array, 2); // ipsum So, this native function would return a value based on a numeric index (second arg), ignoring assoc keys, looking for the real position in array. Are there any native function to do that in PHP or should I write it? Thanks 回答1: $array = array('foo' => 'bar', 33 => 'bin', 'lorem' =>

Get only filename from url in php without any variable values which exist in the url

放肆的年华 提交于 2019-11-26 20:19:16
问题 I want to get filename without any $_GET variable values from a url in php? My url is http://learner.com/learningphp.php?lid=1348 I only want to retrieve the learningphp.php from the url? How to do this? Please help. I used basename but it gives all the variable values also- learntolearn.php?lid=1348 which are in the url. 回答1: This should work: echo basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']); But beware of any malicious parts in your URL. 回答2: Following steps shows

Get the GET variables from a URL String

会有一股神秘感。 提交于 2019-11-26 20:18:06
问题 Hey, say I have a url just being passed through my php is there any easy way to get some GET variables that are being passed through it? It's not the actual url of the page or anything. like a just have a string containing http://www.somesite.com/index.php?url=var&file_id=var&test=var Whats the best way to get the values for those variables? 回答1: parse_str(parse_url($url, PHP_URL_QUERY), $array) , see the manpage for parse_str for more info. 回答2: $href = 'http://www.somesite.com/index.php?url