Monday, February 28, 2022

[FIXED] PHP : I need to read value from ur "www.smple.com/sample.php/value in php

Issue

I need to read the value from url in php code. Below is the sample url . I am passing the value after php file name. I know that we can use query string like "www.smple.com/sample.php?name=value"

But requirement is url need to filename/value, this value will be dynamic. Please any one can help me to solve this issue.

URL : www.smple.com/sample.php/value


Solution

Use parse_url to get the path from the URL and then use explode to split it into its segments.

$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_segments = explode('/', $uri_path);

echo $uri_segments[1];


Answered By - sonam gupta

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.