当前位置:首页 » 编程语言 » php图片链接

php图片链接

发布时间: 2024-12-19 16:02:41

1. 用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);

2. php preg_match_all()函数怎么匹配文章中的所有图片链接并打印出来

<?php
$Html=@file_get_contents('5.html');
$Html=preg_replace('/s{2,}| /i','',$Html);//过滤掉换行和2个以上的空格
preg_match_all('/<imgs+[^>]*srcs?=s?['|"]([^'|"]*)['|"]/i',$Html,$Image);
print_r($Image);

图片,通常情况下,无论有什么属性,他最基本的有2点,<img开头, 有src属性!

那么只要匹配到这2个特征,其他的就别管他,这样,所有图片就出来了

3. 怎么给PHP类型的网站添加图片 然后在给图片做个链接,请详细说明。

这些跟PHP没关系,添加图片用的是html 和 CSS ,给图片加链接用的 html中的 <a>标签。
例如: <img width="100px" height="100px" src="图片的存储位置" /> 这个就表示插入了一个宽100像素高100像素的图片;
<div style="background:url('图片位置') no-repeat;"></div> 表示给这一个块添加一个背景图片....
其它还有几种类似的写法;
而给图片加链接,其实就是用 <a></a> 把图片的那个标签,包含进去,例如:
<a href='http://www..com' title='点击打开网络首页' target="_blank">
<img width="100px" height="100px" src="图片的存储位置" />
</a>
其它具体用法,你可以网络 html img ,html a, css 背景图片 这些详细的用法,就可以了,跟PHP 没关系

4. 在thinkphp中怎样实现点击一张图片下面的超链接“下载”实现这张图片的下载功能求代码、、

可参照如下代码
imageAction.php
<?php
//数据库部分自己改
$link=mysql_connect("localhost","root","123456");
mysql_select_db('test',$link);
mysql_query("set names gb2312"); <br>
$recid = $_GET['recid'];
$query="select * from tb_tpsc where id = $recid";
$result=mysql_query($query);
$info = mysql_fetch_array($result);<br>
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: image/jpeg');
//想办法获取文件扩展名,我这里默认的给的是jpeg的,这个你没有存起来
header("Content-Disposition:filename=". $info['tpmc'] . ".jpeg");
echo $info['file'];
?>

在模板里面写:<a href="路径/imges/recid/图片文件的id">下载</a>
具体的代码以及传递的参数,依据你的实际应用修改。

热点内容
dict合并python 发布:2025-03-12 14:39:25 浏览:879
电脑突然配置更新是什么意思 发布:2025-03-12 14:31:01 浏览:56
访问量跟点击 发布:2025-03-12 14:30:58 浏览:102
安卓如何登录云服务平台 发布:2025-03-12 14:12:35 浏览:520
神奇青蛙安卓版在哪里下载 发布:2025-03-12 14:05:12 浏览:529
曙光牌路由器登录密码是多少 发布:2025-03-12 13:51:36 浏览:99
舞蹈培训源码 发布:2025-03-12 13:34:04 浏览:741
电脑与服务器之间快速传输文件 发布:2025-03-12 13:26:55 浏览:955
ftp上的文件在服务器 发布:2025-03-12 13:26:53 浏览:416
linux关闭445端口 发布:2025-03-12 13:20:47 浏览:219