Change language

PHP Parse_url () function

Syntax:
parse_url ($url, $component = -1) 
Parameters:this function takes two parameter as above and described below:
  • url:this parameter contains the URL to parse. Invalid characters are replaced with _ (underscore).
  • component:this parameter specifies any of the components (PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URLUR_QURMENT or PHP_URL_QURMENT) a specific URL in the form of a string.
Returned values:
  • It returns an associative array if the component parameter is omitted.
  • Returns a string if a component parameter is specified.
  • Returns false if the parameter has an invalid URL.
The following are examples to illustrate the use of the parse_url ( ) in PHP:Example 1:  
// Declare a variable and initialize its URL $url = http://engineerforengineer.org/php/#basics ;  
// Use the parse_url() function to parse the URL var_dump ( parse_url ( $url )); var_dump ( parse_url ( $url , PHP_URL_SCHEME));  
?>
Exit:
array (4 ) {["scheme"] = > string (4) "http" ["host"] = > string (17) "engineerforengineer.org" ["path"] = > string (5) "/ php /" ["fragment"] = > string (6) "basics"} string (4) "http" 
Example 2:  
// Declare a variable and initialize its URL $url = ’//www.engineerforengineer .org / path? php = PHP’ ;  
// Use the parse_url() function for
// parse the URL var_dump ( parse_url ( $url ));  
?>
Exit:
array (3 ) {["host"] = > string (21) "www.engineerforengineer.org" ["path"] = > string (5) "/ path" ["query"] = > string (7) "php = PHP"} 
Link: http://php.net/manual/en/function.parse-url.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method