0

I have following URL string:

http://example.com/sfm?dir=uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/dir

How can I bind everything after the = to a php variable?

so my variable should contain:

$String = 'uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/dir'

3 Answers 3

2

You can use explode to get part after =

$str = "http://example.com/sfm?dir=uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/dir";

$strArr = explode("=",$str);
$url = $strArr[1];
echo $url;
Sign up to request clarification or add additional context in comments.

Comments

2

A more flexible solution, would be to use parse_url and then parse_str:

$url = 'http://example.com/sfm?dir=uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/dir';

$query_string = parse_url($url, PHP_URL_QUERY);

parse_str($query_string, $query_vars);

var_dump($query_vars);

It’ll give you an array with all the GET parameters the URL might contain.

Comments

0

try this

$parts = parse_url('http://example.com/sfm?dir=uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/dir');

parse_str($parts['query'], $query);
echo $query['dir'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.