问题
I have a website for recruitment services. When people respond to a vacancy, the url of the vacancy is echo'd in the response form (hidden field) so I see on what vacancy they respond.
I use this code for it on the response button, it redirects to the response form:
vacature= $ url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];echo $url;
On the website the vacancies have links of the title, combined with the vacancy number: website_url/vacancy_title-number
For example: www.test.com/director-sales-120
In the response form I use this to get the info out of the url:
echo htmlspecialchars ($_GET['vacature']);
For the new crm system we bought, we need only the number, not the rest of the url. How do I get only the number out of the url? Or how do I only get the number into the url ;)
Thanks a lot in advance!
回答1:
$str = "www.test.com/director-sales-120";
$arr=explode("-",$str);
echo $arr[2];
回答2:
preg_match_all('!\d+!', $url, $matches);
print_r($matches);
will print all numbers from the url
$int = filter_var($url, FILTER_SANITIZE_NUMBER_INT);
fetch number from string
来源:https://stackoverflow.com/questions/28564448/request-uri-echourl-only-get-the-number-of-url