導航:首頁 > 編程語言 > 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獲取第一張圖片相關的資料

熱點內容
php100張恩民視頻 瀏覽:640
安卓手機復制門禁卡加密 瀏覽:754
有哪些程序員特有的技能 瀏覽:399
痞幼資源包解壓密碼 瀏覽:699
pdf版本的ppt 瀏覽:176
網站伺服器地址在哪裡 瀏覽:715
python發行版常用包 瀏覽:212
nginx無法解析php 瀏覽:829
單片機編程基礎語言 瀏覽:308
私有雲伺服器怎麼設置 瀏覽:957
程序員的晚上生活 瀏覽:585
visualc的編譯鍵不見了 瀏覽:856
51單片機畢業設計論文 瀏覽:666
3doutline怎麼擴展命令 瀏覽:861
程序員生活費200 瀏覽:339
方舟編譯器與小米 瀏覽:184
佳明app訓練怎麼用 瀏覽:989
如何查看data有沒有加密 瀏覽:502
新福克斯壓縮比發動機 瀏覽:1000
斐波那契回調演算法公式 瀏覽:505