導航:首頁 > 編程語言 > php獲取第一張圖片

php獲取第一張圖片

發布時間:2025-07-11 11:19:44

php怎麼隨機獲取一張圖片並返回圖片網址

把這些圖片放到一個數組陵畝下面,

例如

$arr[]='1.jpg';
$arr[]='2.jpg';
$arr[]='3.jpg';
$arr[]='4.jpg'段仔;
$arr[]='5.jpg';
$arr[]='6.jpg';
$arr[]='握汪汪7.jpg';
$a=rand(0,count($arr)-1);
echo$arr[$a];

❷ 用PHP獲取鏈接及圖片路徑的方法

<?php

$str="Thisisatest.Thisisatest.Thisisa<ahref=http://link1.com><imgsrc=http://img1.jpg/></a>test.Thisisatest.Thisisatest. ".
"Thisisatest.Thisisatest.<ahref=http://link2.com><imgsrc=http://img2.jpg/></a>Thisisatest.Thisisatest.Thisisatest. ".
"<ahref=http://link3.com><imgsrc=http://img3.jpg/></a>";

$regex='/<as+href=(.*)s*><imgs+src=(.*)s*/></a>/';
$output=array();

if(preg_match_all($regex,$str,$matches)!==false){
if(isset($matches[1])&&isset($matches[2])){
$links=$matches[1];
$imgs=$matches[2];

foreach($linksas$key=>$link){
$img=isset($imgs[$key])?$imgs[$key]:'';
$output[]="<ahref="{$link}"><imgsrc="{$img}"/></a>";
}
}
}

var_mp($output);

❸ PHP怎麼隨機獲取一張圖片並返回圖片網址

從一個目錄里獲取某類型文件的清單(用在WEB的話一般是jpg/gif/png)->通過隨機函數選一個圖片->輸出代碼。
PHP代碼如下:

復制代碼 代碼如下:

$imglist='';
//用$img_folder變數保存圖片所在目錄,必須用「/」結尾
$img_folder = "images/tutorials/";
mt_srand((double)microtime()*1000);
//使用目錄類
$imgs = dir($img_folder);
//檢查目錄下是否有圖片,並生成一個清單
while ($file = $imgs->read()) {
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
$imglist .= "$file ";
} closedir($imgs->handle);
//把清單里的項都放到一個數組里
$imglist = explode(" ", $imglist);
$no = sizeof($imglist)-2;
//生成一個介於0和圖片數量之間的隨機數
$random = mt_rand(0, $no);
$image = $imglist[$random];
//輸出結果
echo '<img src="'.$img_folder.$image.'" border="0/" alt="" />';

❹ php中如何調用資料庫中的圖片並且顯示到頁面

php是採用二進制形式存儲圖片及讀取顯示的,首先通過代碼創建數據表,然後上傳圖片伺服器再通過瀏覽器顯示,具體編程代碼舉例:

1、首先需要創建數據表,具體代碼如下圖所示。

❺ php讀取圖片的路徑

  1. 你的代碼是遍歷$dir文件夾下面的文件,然後輸出成<img src=""/>,訪問伺服器上的圖片一般是網址+具體路徑,例如:localhost/public/logo.jpg,是指訪問網址根目錄下的public/logo.jpg文件,對應你這里的就是htdocs/public/logo.jpg

  2. 圖片的顯示大小可以設置img的width和heigth屬性,位置可以設置相應的css值,例如<img src="/public/logo.jpg" width="100px" heigth="100px" style="display:block;margin:0 auto">

閱讀全文

與php獲取第一張圖片相關的資料

熱點內容
cdr怎麼轉pdf格式 瀏覽:405
蒙商信用卡app里怎麼修改收貨地址 瀏覽:331
php高級面試題2017 瀏覽:937
紫色可以緩解壓力嗎 瀏覽:681
內核編譯版本cpu架構 瀏覽:573
中級程序員面試題 瀏覽:162
在線壓縮音樂文件 瀏覽:746
php刪除非空文件夾 瀏覽:3
php你好世界代碼 瀏覽:817
k270cz1壓縮機功率 瀏覽:321
不知從哪裡開始學習python 瀏覽:427
java打開文件方式 瀏覽:702
keil分段編譯 瀏覽:27
app有了用戶後怎麼賺錢 瀏覽:306
程序員那麼可愛20觀看 瀏覽:999
一個數除以二的演算法 瀏覽:403
如何選擇php培訓機構 瀏覽:982
app被移除管理了怎麼弄 瀏覽:934
phpredis消息推送 瀏覽:804
剪貼板里怎麼加密碼 瀏覽:153