Replace Variable on Url

I have this question about parse url ...

The url is.

i want to parse this url so as to able to check it anytime throuh my
pages and replace the lang with

I want to use this function in many pages, so as to be able to change
the language anytime.

Thank you.
p.s. i am a newbbie.