如何读取当前URL并从中获取特定元素

I have the following URL creating dynamically "http://mxcounters.com/gorilla-crowd/?page_id=4994?company_id=11" i want to read company_id from it. as each time it will be changed coming from previous page: I have tried as follows but its showing empty variable

   $company_id = $_GET['company_id'];
   echo $company_id;

Your URL's query string is wrongly formatted. The query string parameters need to be separated by & (& when URL encoded) not ? as in your example. As a result $_GET['company_id'] isn't getting set.

Your URL should look like:-

http://mxcounters.com/gorilla-crowd/?page_id=4994&company_id=11

Then $_GET['company_id'] should contain 11 as expected.

I got the ID with another method that's work in my case perfectly

 $rest = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 $company_id = substr($rest, -2, 2);

I get the whole link in a variable and then get the last 2 characters from this string as above and worked fine