results;} elseif ($type == 'tailor') {// 使用 Yelp API 搜索附近的裁缝店$url = 'https://api.yelp.com/v3/businesses/search?term=tailor&location=New York City&limit=5';// 设置 HTTP 头部,包括授权信息
$headers = ['Authorization: Bearer YOUR_API_KEY','Content-Type: application/json'];// 执行 HTTP 请求并获取响应数据$ch = curl_init($url);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($ch);curl_close($ch);// 将响应数据解码为 JSON 对象$data = json_decode($response);// 提取搜索结果$results = $data->businesses;}// 输出搜索结果if (count($results) > 0) {echo '
搜索结果:
';echo '
';foreach ($results as $result) {echo '
-
' . $result->name . '
';}echo '
';} else {echo '未找到任何结果。';}}?>