Hello.
There is a string

http://examle.com/primer?product_id=200 

Is there any way to take a substring of 200 from it?
This number is always different.

    2 answers 2

    Use the parse_url () and parse_str () functions

     <?php $str = 'http://examle.com/primer?product_id=200'; $query = parse_url($str, PHP_URL_QUERY); parse_str($query, $variables); var_dump($variables); 

    Result

     array (size=1) product_id' => string '200' (length=3) 
    • did not quite understand how to take $ variables - votanko
    • @votanko, an array of $variables will be created after calling parse_str and will contain you request as key => value . - user207618

    If the string is always like this, only different values, then so:

     $str = 'http://examle.com/primer?product_id=200'; $result = explode('=', $str)[1]; echo $result; // Выведет: 200