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.
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.
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)
$variables
will be created after calling parse_str
and will contain you request as key => value
. - user207618If 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
Source: https://ru.stackoverflow.com/questions/561623/
All Articles