How to get parameters from a URL string in PHP?
The parameters from a URL string can be retrieved in PHP using parse_url() and parse_str() functions.
Note: Page URL and the parameters are separated by the ? character.
parse_url() Function: The parse_url() function is used to return the components of a URL by parsing it. It parse an URL and return an associative array which contains its various components.
parse_url( $url, $component = -1 )
parse_str() Function: The parse_str() function is used to parse a query string into variables. The string passed to this function for parsing is in the format of a query string passed via a URL.
parse_str( $string, $array )
Approach: Parse the URL string using parse_url() function which will return an associative array that contains its (passed URL) various components. The query of the array returned by parse_url() function which contains a query string of URL.
Below examples uses parse_url() and parse_str() function to get the parameters from URL string.
Hi Amit your emailID is firstname.lastname@example.org
PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!