当前位置:首页 » 编程语言 » php获取图片地址

php获取图片地址

发布时间: 2022-07-30 09:30:10

㈠ 请教如何用php提取图片url地址

1楼的不太符合实际情况,
$str='<p><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
print_r($match);

结果:
Array(
[0] => Array ( [0] => <img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/> )
[1] => Array ( [0] => upfiles/2009/07/1246430143_1.jpg )
)

直接获取图片 echo current($match[1]);

㈡ php 怎样获取文本内容中的图片和文件路径

$str='<imgsrc="http://localhost/2.jpg"alt=""/><imgsrc="http://localhost/2.jpg"alt=""/><imgsrc="http://localhost/2.jpg"alt=""/><ahref="http://www.,com/">aaa</a>';
$str=strip_tags($str,'<img>');
preg_match_all('/<imgs+src="([w:/.]+)"/',$str,$matches);
//var_mp($matches[1]);
$match=$matches[1];
foreach($matchas$value){
echo$value."<br>";
}

㈢ 用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如何用正则表达式抓取网页中的图片地址

当前标签的属性为:img(图片)
标签名称恭伐多和鼙古俄汰藩咯:Image3
图片地址是:index_files/dh_01.jpg
图片的宽:95,高:32。
标签的链接:index.asp

㈤ 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提取网页图片的地址

用正则,$partern='/<img[^>]*src="([^"]*)"[^>]*>/'; 试试这个

㈦ PHP 图片上传 获取地址

getimagesize(文件路径)
$_FILES["file"]["name"]只是一个文件名,是一个字符串,而不是图片。

指定临时存放目录可以得到。

给你两个参考吧

关键注意move_uploaded_file()函数的用法

㈧ PHP怎样根据URL获取图片真实地址

楼主可以用curl把这个图片文件的内容拿出来,然后用file_put_contents()函数把他写入一个文件里,格式为你想要保存的图片格式,写个例子给你吧:


首先用curl拿到这个图片的代码:

$url=测试URL地址

$curl=curl_init($url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,10);
$content=curl_exec($curl);
curl_close($curl);

file_put_contents('图片保存的路径+a.jpg',$content);


大概就这样子了,我就不测试了,楼主测试一下可行不,file_put_contents()函数不明白就查查手册,如果有报错什么的就带上报错信息回复我吧。

㈨ php如何获取上传图片的路径

那是临时的文件,你需要保存下来才行
move_uploaded_file($_FILES["img"]["tmp_name"],$file);
这个函数可以保存下来吧图片,$file定义为自己需要保存到的地方

热点内容
如何配置组合音响 发布:2025-07-12 12:53:54 浏览:93
c语言幂计算 发布:2025-07-12 12:52:36 浏览:566
兔费WLAN密码多少 发布:2025-07-12 12:50:59 浏览:861
阿里云分布式存储 发布:2025-07-12 12:45:04 浏览:535
sql日志压缩 发布:2025-07-12 12:39:53 浏览:343
红点角标算法 发布:2025-07-12 12:11:16 浏览:844
开心消消乐服务器繁忙什么情况 发布:2025-07-12 12:11:14 浏览:239
数据库的封锁协议 发布:2025-07-12 12:10:35 浏览:725
如何配置一台长久耐用的电脑 发布:2025-07-12 11:43:03 浏览:602
昆明桃源码头 发布:2025-07-12 11:38:45 浏览:569