REQUEST_URI: echo$url : only get the number of url

2019-08-29 07:04发布

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!

标签: php get echo
2条回答
放荡不羁爱自由
2楼-- · 2019-08-29 07:16
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

查看更多
Animai°情兽
3楼-- · 2019-08-29 07:21
$str = "www.test.com/director-sales-120";
$arr=explode("-",$str);
echo $arr[2];
查看更多
登录 后发表回答