如何从具有两个通配符参数的网址获得响应?

时间:2019-05-10 22:56:56

标签: php

我正在尝试从具有两个需要通配符的部分的URL返回html。我很确定正则表达式是必经之路(除非有我不知道的替代方法?)...但是我似乎无法正确地做到这一点。我对正则表达式一无所知,希望有人可以帮助我。

通配符需要支持任意数量的字母数字字符,包括下划线和尽可能多的特殊字符。

所有这些都是可能的情况:

https://www.example.com/type/1062483_name
https://www.example.com/type/name_ii
https://www.example.com/type/name

我已经尝试过在线使用所有正则表达式工具,但似乎无法匹配它。这是我目前的代码:

$url = $baseurl . $type . $wildcard1 . $name . $wildcard2

function get_http_response_code($url) {
    $headers = get_headers($url);
    return substr($headers[0], 9, 3);
}
if(get_http_response_code($url) == "200"){
    $html = file_get_contents($url);
}

我需要(get_http_response_code($url) == "200")才能返回true。

关于如何进行这项工作的任何建议都将是惊人的。谢谢!

0 个答案:

没有答案