Sure! Here's an example of how you can put the code inside a function in 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.