parse_url 


php128 apg

PARSES an URL and return its components.





This function parses a URL and returns an associative array containing any of the various components of the URL that are present.

The values of the array elements are not URL decoded.

This function is not meant to validate the given URL, it only breaks it up into the above listed parts.

Partial URLs are also accepted and this function tries its best to parse them correctly.

Invalid characters in the provided URL, are replaced by underline character, ( _ ).



<?php

mix parse_url 
str $url int $component = -)


where,

$url The URL to be parsed
          Inválid characters are replaced by underline
, ( )

$component One of the URL component
                       
SEE the below TABLE )

?>

  $url   


The URL to be parsed.



  $component   

CONSTANT NAME VALUE MEANING
PHP_URL_SCHEME 0 scheme
PHP_URL_HOST 1 host
PHP_URL_PORT 2 port
PHP_URL_USER 3 user
PHP_URL_PASS 4 pass
PHP_URL_PATH 5 path
PHP_URL_QUERY 6 query
AFTER the ?
PHP_URL_FRAGMENT 7 fragment
AFTER the #
ed48


  1 EXERCISE   

<?php

$urltoparse01 
'https://trip.ed48.com/trip/?tlb=15#6';

echo 
parse_url($urltoparse01PHP_URL_SCHEME);

echo 
'<br>' parse_url($urltoparse01PHP_URL_HOST);

echo 
'<br>' parse_url($urltoparse01PHP_URL_QUERY);

?>

  2 EXERCISE   

<?php

$urltoparse02 
'https://trip.ed48.com/trip/?tlb=15#6';

echo 
'<br><br><pre>';
var_dump(parse_url($urltoparse02));
echo 
'</pre>';

?>

  3 EXERCISE   

<?php

$urltoparse03 
'https://hirotur.com.br/paginas/informacoes-sobre-destinos/';

$arr03 = [ => 'PHP_URL_SCHEME'=> 'PHP_URL_HOST'
                
=> 'PHP_URL_PORT'=> 'PHP_URL_USER',
                
=> 'PHP_URL_PASS'=> 'PHP_URL_PATH'
                
=> 'PHP_URL_QUERY'=> 'PHP_URL_FRAGMENT' ];
           

for(
$i=0$i 8$i++)
{

echo 
$arr03[$i] . '<br>';
var_export(parse_url($urltoparse03$i));
echo 
'<br><br>';

}

?>