導航:首頁 > 編程語言 > php是否圖片url

php是否圖片url

發布時間:2024-12-25 15:18:02

① 有一堆圖片url,用php怎樣實現批量預覽

如果你有一堆圖片的 URL,你可以使用 PHP 的 foreach 循環來遍歷這些 URL,然後使用 PHP 的 echo 語句將圖片的 HTML 標簽輸出到瀏覽器中。例如:
$imageUrls = [
"url地址",
"url地址",
"url地址"
];
foreach ($imageUrls as $url) {
echo "<img src='$url' alt='A preview image'>";
}
這樣,在瀏覽器中,你就可以看到這些圖片了。
請注意,上面的代碼僅供參考,在實際應用中你可能需要做一些更多的工作來實現你的需求。例如,你可能需要設置圖片的寬度和高度,或者添加其他的樣式來改變圖片的外觀。
總之,在 PHP 中實現批量預覽圖片,你可以使用 foreach 循環和 echo 語句來輸出圖片的 HTML 標簽,這樣就可以在瀏覽器中預覽這些圖片了。

② php打開URL的幾種方法

PHP中打開URL地址的幾種方法總結,這里的函數主要用於小偷採集等函數。
1:用file_get_contents
以get方式獲取內容
復制代碼代碼如下:

<?php
$url='http://www..com/';

$html=file_get_contents($url);
//print_r($http_response_header);

ec($html);
printhr();
printarr($http_response_header);

printhr();
?>

示例代碼2:用fopen打開url,
以get方式獲取內容
復制代碼代碼如下:

<?
$fp=fopen($url,'r');

printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)){

$result.=fgets($fp,1024);
}
echo"urlbody:$result";

printhr();
fclose($fp);
?>


示例代碼3:用file_get_contents函數,以post方式獲取url
復制代碼代碼如下:

<?php
$data=array('foo'=>
'bar');
$data=http_build_query($data);
$opts=array(
'http'
=>array(
'method'=>'POST',
'header'=>"Content-type:
application/x-www-form-urlencoded".
"Content-Length:".strlen($data).
"",
'content'=>$data
),
);
$context=
stream_context_create($opts);
$html=
file_get_contents('http://localhost/e/admin/test.html',false,$context);

echo$html;
?>


示例代碼4:用fsockopen函數打開url,以get方式獲取完整的數據,包括header和body
復制代碼代碼如下:

<?
functionget_url
($url,$cookie=false){
$url=parse_url($url);
$query=
$url[path]."?".$url[query];
ec("Query:".$query);
$fp=fsockopen(
$url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
if(!$fp){

returnfalse;
}else{
$request="GET$queryHTTP/1.1";

$request.="Host:$url[host]";
$request.="Connection:Close";

if($cookie)$request.="Cookie:$cookie ";
$request.="";

fwrite($fp,$request);
while(!@feof($fp)){
$result.=@fgets($fp,
1024);
}
fclose($fp);
return$result;
}
}

//獲取url的html部分,去掉header
functionGetUrlHTML($url,$cookie=false){

$rowdata=get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return$body;

}
returnfalse;
}

?>

③ php 判斷是網址還是文件路徑

可以直接使用 parse_url 函數,請參考以下代碼:

<?php

$url="http://www..com";
$path="/home/wwwroot/a.php";

functionisUrl($url)
{
$parse=parse_url($url);
returnisset($parse['scheme']);
}

if(isUrl($url)){
echo'是網址';
}
//輸出:是網址

if(!isUrl($path)){
echo'不是網址';
}
//輸出:不是網址

④ php怎麼判斷一個url是不是圖片

可以分析HTTP頭信息中的Content-Type。

php有獲取頭信息的函數get_headers():

//$url為圖片地址
$header=get_headers($url,1);
//$headers['Content-Type']是URL的類型
$type=explode('/',$headers['Content-Type']);
if($type[0]==='image'){
//這是一個圖片
}
else{
//這不是一個圖片
}

關於get_headers()的具體信息,可以參見:

PHP手冊:get_headers():http://php.net/manual/zh/function.get-headers.php

如果要寫成一個函數,就是:

functionis_image($url){
$header=get_headers($url,1);
$type=explode('/',$headers['Content-Type']);
if($type[0]==='image'){
//這是一個圖片
returnTRUE;
}
else{
//這不是一個圖片
returnFALSE;
}
}

這樣就可以了。

閱讀全文

與php是否圖片url相關的資料

熱點內容
音樂緩存文件夾的軟體 瀏覽:394
Dkms編譯列印機驅動 瀏覽:992
解壓縮文件操作異常 瀏覽:555
等待代碼編譯時你會幹嘛 瀏覽:493
單片機c語言中變數右移8位 瀏覽:81
解壓的一個小短片 瀏覽:831
二級壓縮空壓機哪家好排行 瀏覽:743
基於單片機超聲波測距 瀏覽:130
模擬隨機紅包演算法 瀏覽:386
程序員接外包網站 瀏覽:135
哪裡可以買拆車件app 瀏覽:992
限流演算法漏桶和令牌桶區別 瀏覽:316
程序員怎麼找兼職 瀏覽:802
java編譯路徑 瀏覽:283
伺服器修改mac地址是什麼 瀏覽:581
商城訂單介面api加密 瀏覽:29
電話鍵盤加密應用 瀏覽:491
廣聯達安裝教程未檢測到加密鎖 瀏覽:343
ubuntu1404命令 瀏覽:55
rd會話主機伺服器是什麼 瀏覽:147