当前位置:首页 » 编程语言 » 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>
具体的代码以及传递的参数,依据你的实际应用修改。

热点内容
三位密码锁忘记密码如何重置 发布:2025-09-18 10:21:52 浏览:184
linux怎么编译c文件 发布:2025-09-18 09:55:16 浏览:303
python安装后无法运行 发布:2025-09-18 09:45:57 浏览:238
安卓手机怎么剪辑音乐 发布:2025-09-18 09:44:16 浏览:782
服务器地址修改在哪找 发布:2025-09-18 09:42:41 浏览:442
sntp服务器地址 发布:2025-09-18 09:28:36 浏览:555
phpunit 发布:2025-09-18 09:25:19 浏览:573
怎么改服务器的ip地址吗 发布:2025-09-18 09:24:33 浏览:14
编译703n固件 发布:2025-09-18 08:50:59 浏览:541
三星手机系统文件夹是哪个文件夹 发布:2025-09-18 08:48:45 浏览:284