放在function里
Sure! Here's an example of how you can put the code inside a function in PHP:
```php
function submitUrlBatch($apikey, $url, $urlList) {
$data = array(
"siteUrl" => $url,
"urlList" => $urlList
);
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=" . $apikey);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string)
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
// Usage:
$apikey = "sampleapikeyEDECC1EA4AE341CC8B6";
$url = "http://yoursite.com";
$urlList = array(
"http://yoursite.com/url1",
"http://yoursite.com/url2",
"http://yoursite.com/url3"
);
$result = submitUrlBatch($apikey, $url, $urlList);
echo $result;
```
You can call the `submitUrlBatch()` function with your API key, the main URL, and an array of URLs to submit. The function will return the response from the API call, which you can then handle as needed.
AI智能问答网
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用创作工场,更聪明、更完整、更原创!