Nano HE
Nano HE

Reputation: 9307

PHP Array Key & value Question

Hi I writed a test code as below.

<?php
$url = 'http://localhost/events/result/cn_index.php?login';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);


?>

Output

Array ( [scheme] => http [host] => localhost [path] => /events/result/cn_index.php [query] => login ) /events/result/cn_index.php

Now I inserted the line below

echo array[query]; // I want to echo 'login', but failed.

How to get the value of 'login'?

Upvotes: 0

Views: 86

Answers (2)

SilentGhost
SilentGhost

Reputation: 320009

$parsed = parse_url($url);
echo $parsed['query'];

Upvotes: 2

hsz
hsz

Reputation: 152304

Try with:

$output = parse_url($url, PHP_URL_PATH);
echo $output['query'];

Upvotes: 2

Related Questions