很多站长朋友们都不太清楚php获取指定路径图片,今天小编就来给大家整理php获取指定路径图片,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 用PHP获取链接及图片路径的方法 2、 php如何从文件夹中提取指定的图片 3、 php读取图片的路径 4、 关于PHP中图片获取路径的问题 用PHP获取链接及图片路径的方法<?php
$str = "This is a test.This is a test.This is a <a href=;<img src= /></a>test.This is a test.This is a test.\n" .
"This is a test.This is a test.<a href=;<img src= /></a>This is a test.This is a test.This is a test.\n" .
"<a href=;<img src= /></a>";
$regex = '/<a\s+href=(.*)\s*><img\s+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 ($links as $key => $link) {
$img = isset($imgs[$key]) ? $imgs[$key] : '';
$output[] = "<a href=\"{$link}\"><img src=\"{$img}\" /></a>";
}
}
}
var_dump($output);
php如何从文件夹中提取指定的图片<?php
$dir = "./images/"; //要获取的目录
echo "********** 获取目录下所有文件和文件夹 ***********<hr/>";
//先判断指定的路径是不是一个文件夹
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh))!= false){
//文件名的全路径 包含文件名
$filePath = $dir.$file;
echo "<img src='".$filePath."'/>";
}
closedir($dh);
}
}
?>
亲!!如果感觉有用,请采纳!!
php读取图片的路径你的代码是遍历$dir文件夹下面的文件,然后输出成<img src=""/>,访问服务器上的图片一般是网址+具体路径,例如:localhost/data/upload/help/202303/02/fb540049bd4f696a825c0684097bab1c.jpg,是指访问网址根目录下的public/logo.jpg文件,对应你这里的就是htdocs/data/upload/help/202303/02/fb540049bd4f696a825c0684097bab1c.jpg
图片的显示大小可以设置img的width和heigth属性,位置可以设置相应的css值,例如<img src="/data/upload/help/202303/02/fb540049bd4f696a825c0684097bab1c.jpg" width="100px" heigth="100px" style="display:block;margin:0 auto">
关于PHP中图片获取路径的问题<?php
//动态表格输出!#@$%@#^@$%
!@#$!@$!#@$
$i = 1; //这个是你里边的img 文件中的起,如果是1.jpg,那就是=1 如果是10开头,则为=10
while($myrow=mysql_fetch_array($rs)){
$i++;
?>
<table>
<tr>
<td><img ="img/<?php echo $i?>.jpg"></td>
<td>bbbb</td>
</tr>
</table>
<?php
}
?>
关于php获取指定路径图片的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php获取指定路径图片 php获取路径的详细内容...