0

I have this url and i want to take variable values in php from this url how to do this.

http://example.com/core/click/3492/3389
3
  • What variable value do you want to get? 3492 or 3389? Or is it something else? Commented Sep 21, 2017 at 2:12
  • Please show any code samples you may have come up with in an attempt to solve your problem. Is "core" important?, is "click" important? Commented Sep 21, 2017 at 2:13
  • i want to get 3492 value in php Commented Sep 21, 2017 at 2:15

1 Answer 1

2

Use parse_url() function to return the path part of the url.

<?php
// returns: /core/click/3492/3389
$path = parse_url('http://example.com/core/click/3492/3389', PHP_URL_PATH);

Then you can explode() the path into its parts:

$path = explode('/', ltrim($path, '/'));

print_r($path);

Array
(
    [0] => core
    [1] => click
    [2] => 3492
    [3] => 3389
)
Sign up to request clarification or add additional context in comments.

6 Comments

The second parameter to parse_url is a great way to get just the path too without the additional variable assignment.
what to do if this 3492 value is a variable value
@Mark you won't have issues if the value changes only that if you're trying to access it like say $path[2] and then the url changes to /core/foo/click/3492/3389, but you didn't mention that in the question.
sir only 3492 and 3389 are variables and remaining path is not changed.
Ok, you should not have an issue accessing them like $path[2] and $path[3].
|

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.