如何获取$ _GET URL(有时它会生成一个包含多个元素的数组)

I've just start to learn some php, and I'm trying to make a simple php script. All it will do is ask a person for a link, and then it will convert it in a hyper link.


How people can use my website:

The first way is they can

  1. Go to localhost/link-to-hyperlink.php
  2. Put in the url in my form. Like: https://google.com
  3. Then my php script converts it into a hyper link.

Second way they can is they can:

  1. Go to localhost/link-to-hyperlink.php?url=https://google.com
  2. Then my php script converts it into a hyper link.

My Problem

Both my things work, but when someone submits a url like this https://google.com/something.php?name=bob&age=12&fav-nums=200;300;400 my program doesn't work properly. It makes the hyper link https://google.com/something.php?name=bob, not the entire URL.

Also happens on partially encoded urls like: localhost/link-to-hyperlink.php?url=https://google.com?something.php?names=bob%3Bmike%3Bsam&age=30%3B23%3B22&fav-nums=200%3B300%3B400.

It only happens when someone decides to use the second way to convert the link. I printed the $_GET array and you can see that it makes multiple indexes in the $_GET. I would like to facilitate their mis-use.

The array look liks this:

Array
(
    [url] => https://google.com/something.php?name=bob
    [age] => 12
    [fav-nums] => 200;300;400
)

My program: link-to-hyperlink.php

<?php

    if(isset($_GET['url']) == false) {
        $answer = "Enter a URL<br>";
    } else {
        $answer = '<a target="_blank" href="' . $_GET['url'] . '">Your Hyperlink</a><br>';
    }

?>

<html>
<head>
    <title>Link To Hyerplink Converter</title>
</head>

<body>
    <pre>
The array structure was:

<?php print_r($_GET); ?>
    </pre>
    <br>
    <?php echo $answer; ?>
    <form action="link-to-hyperlink.php" method="GET">
        Your URL:<br>
        <input type="text" name="url"><br>
        <input type="submit" value="submit">
    </form>
</body>
</html>