您好我必须检查是否找到了网址。如果网址可用,我需要在URL
中加载iframe
。我们怎么做?
我的示例代码
<?php
$url = 'http://example.com/t/urlname';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
/* Handle 404 here. */
echo "Url Not found";
} else { ?>
<div id="iframe-comments">
<iframe src="<?php echo $url; ?>" scrolling="no" style="width: 800px; height: 800px;">
</iframe>
</div>
<?php
}
curl_close($handle);
?>
在这种情况下,如果网址可用,则表示未加载/显示iframe
Div
。请建议加载iframe
答案 0 :(得分:0)
试试这段代码:
您可以在不使用cURL的情况下执行相同的操作
$url = 'http://thedemon.in';
$file_headers = @get_headers($url);
if($file_headers[0] == 'HTTP/1.1 200 OK') {
?>
<div id="iframe-comments">
<iframe src="<?php echo $url; ?>" scrolling="no" style="width: 300px; height: 300px;"> </iframe>
</div>
<?php
}
else {
echo "Url Not found";
}