I have a site and I would need to get one pages URL with PHP. The URL might be something www.mydomain.com/thestringineed/
or it can www.mydomain.com/thestringineed?data=1
or it can be www.mydomain.com/ss/thestringineed
So it's always the last string but I dont want to get anything after ?
You will use the parse_url function, then look at the path portion of the return. like this:
and your out put is
use
$_SERVER['REQUEST_URI']
it will return full current page url you can split it with '/' and use the last array index . it will be the last stringparse_url()
is the function you are looking for. The exact part you want, can be received throughPHP_URL_PATH
parse_url
should help you out.You can use:
Which will remove all the '/' in the url and return an array containing all the words.
Now has the value of the string you need, but it may contain '?data=1' so we need to remove that:
Has the string you are wanting out of the url.
Hope this Helps!