Asked  7 Months ago    Answers:  5   Viewed   40 times

I have a HTML form field $_POST["url"] having some URL strings as the value. Example values are:


How can I get only the email parameter from these URLs/values?

Please note that I am not getting these strings from browser address bar.



You can use the parse_url() and parse_str() for that.

$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['email'];

If you want to get the $url dynamically with PHP, take a look at this question:

Get the full URL in PHP

Tuesday, June 1, 2021
answered 7 Months ago

The domain is stored in $_SERVER['HTTP_HOST'].

EDIT: I believe this returns the whole domain. To just get the top-level domain, you could do this:

// Add all your wanted subdomains that act as top-level domains, here (e.g. '' or '')
// As array key, use the last part ('cc' and 'uk' in the above examples) and the first part as sub-array elements for that key
$allowed_subdomains = array(
    'cc'    => array(
    'uk'    => array(

$domain = $_SERVER['HTTP_HOST'];
$parts = explode('.', $domain);
$top_level = array_pop($parts);

// Take care of allowed subdomains
if (isset($allowed_subdomains[$top_level]))
    if (in_array(end($parts), $allowed_subdomains[$top_level]))
        $top_level = array_pop($parts).'.'.$top_level;

$top_level = array_pop($parts).'.'.$top_level;
Wednesday, March 31, 2021
answered 9 Months ago

The "domainNameSuffix" is called a top level domain (tld for short), and there is no easy way to extract it.

Every country has it's own tld, and some countries have opted to further subdivide their tld. And since the number of subdomains ( is also variable, there is no easy "one-regexp-fits-all".

As mentioned, you need a list. Fortunately for you there are lists publicly available:

Wednesday, March 31, 2021
answered 9 Months ago

In a GET request, the request parameters are taken from the query string (the data following the question mark on the URL). For example, the URL contains two request parameters - - p1 and p2. In a POST request, the request parameters are taken from both query string and the posted data which is encoded in the body of the request.

This example demonstrates how to include the value of a request parameter in the generated output:

Hello <b><%= request.getParameter("name") %></b>!

If the page was accessed with the URL:

the resulting output would be:

Hello <b>John Smith</b>!

If name is not specified on the query string, the output would be:

Hello <b>null</b>!

This example uses the value of a query parameter in a scriptlet:

    if (request.getParameter("name") == null) {
        out.println("Please enter your name.");
    } else {
        out.println("Hello <b>"+request. getParameter("name")+"</b>!");
Tuesday, June 1, 2021
answered 7 Months ago

Unless you have a special data source to work on, you have to read the website's contents then process it manually. Here is a link from the java tutorials on how to read from an URL connection.


public class URLConnectionReader {
    public static void main(String[] args) throws Exception {
        URL oracle = new URL("");
        URLConnection yc = oracle.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
        String inputLine;
        while ((inputLine = in.readLine()) != null) 


If you are behind a proxy you should also set these system properties (to the appropriate values):

System.setProperty("http.proxyHost", "");
System.setProperty("http.proxyPort", "1111");
Tuesday, August 10, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :