我试图用一串文本检查2件事。首先,我想检查它是否是一个真正的URL。那么,如果是这样,我想检查该URL是否是图像。我来到this answer,并说要做到以下几点:检查URL是否存在,如果它是一个图像
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$imageURL);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE) {
print_r("went Throught");
}
else {
print_r("Failed");
}
curl_close($ch);
不管是什么$imageURL
是,我总是Failed
。我如何实现以下功能:
if ($imageURL isRealUrl) {
// Do some code
if ($imageURL isInArrayOfImages(.png, .jpg, .GIF) {
// Do something
}
}
那么,你正在使用$ imageURL和$ url。这是什么? – rjdown
为什么不用'getimagesize()'来回答? – harrrrrrry
这是$ imageURL。 – Horay