I am given a page url like 'http://abc.com/test.php?a=1&b=2&c=3'. Now I have been told to change the value of b to 5 so that it becomes 'http://abc.com/test.php?a=1&b=5&c=3'.
i.e change from http://abc.com/test.php?a=1&b=2&c=3 to http://abc.com/test.php?a=1&b=5&c=3
Note: variable b here can refer to any name.
Answers
1
Use
parse_url() to extract the query string from the URL
parse_str() to split the query string into an array
array_merge() to add a new array "b" => 5
http_build_query() to re-build a query string
The remaining parts from the first step (protocol, host, path...) to re-build the full URL or - if you have the HTTP pecl extension - a http_build_url() with HTTP_URL_JOIN_QUERY will alleviate much of the work.
Edit: As explained by Beta in the other answer, it is possible.
No. There is no way to do this in the Makefile. You can however change the value of a variable on the make command line. If you rewrite your Makefile as follows:
In some cases it is possible to get local variable addresses using HotSpot Serviceability Agent. I've made a sample agent that prints extended stack traces with local variable info:
Here main is Java thread name; 30920 is native thread ID; @ 15 is bytecode index.
The line [1] 0x00007f075a857910 = (int) 0x1 means that the local variable #1 is located at address 0x00007f075a857910 and has the value 1. This is exactly the variable you are interested in.
The local variable information is reliable for interpreted methods, but not always for compiled methods. However, compiled methods will have an extra line with an address of the code, so you can disassemble and inspect it in gdb.
Use
parse_url()
to extract the query string from the URLparse_str()
to split the query string into an arrayarray_merge()
to add a new array"b" => 5
http_build_query()
to re-build a query stringThe remaining parts from the first step (protocol, host, path...) to re-build the full URL or - if you have the
HTTP
pecl extension - ahttp_build_url()
withHTTP_URL_JOIN_QUERY
will alleviate much of the work.