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

北战南征 提交于 2020-01-06 12:52:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!