当前位置:首页 » 编程语言 » php获取href

php获取href

发布时间: 2022-06-16 13:41:26

‘壹’ 用php取出下列a标签的href值和title值,求指点,谢谢。

用正则表达式截取
<?php
$new="<a
href="/news_detail/newsId=df05b0dc-bc26-4667-bfb4-db5008525053.html"
title="英镑/美元自上周四的英国第一季度GDP数据以来强劲上扬"
target="_self">
英镑/美元自上周四的英国第一季度G...</a>";
$pattern='href\=\"([a-zA-z0-9\/]{5,}\.html)\"
';
//截取href的正则
preg_match_all($pattern,$new,$match);
var_mp($match);
$pattern2='title\=\"([a-zA-z0-9\/]{5,})\"';
//截取title的正则
preg_match_all($pattern2,$new,$match2);
var_mp($match2);
?>

‘贰’ php正则表达式获取div标签中的a标签href问题

先取出div,然后再处理
<a href="([^"]+)"[^>]+

话说这是基础……您还是好好看书看例子吧

‘叁’ php用正规表达式获取网页指定内容

<?php
$str
=
<<<str
<th>1</th>
<td
class="key"><a
href="网址1"
target="_blank">你要的地址1</a></td>
<th>2</th>
<td
class="key"><a
href="网址2"
target="_blank">你要的地址2</a></td>
<th>3</th>
<td
class="key"><a
href="网址3"
target="_blank">你要的地址3</a></td>
<th>4</th>
<td
class="key"><a
href="网址4"
target="_blank">你要的地址4</a></td>
<th>5</th>
<td
class="key"><a
href="网址5"
target="_blank">你要的地址5</a></td>
str;
$p
=
'#<td
class="key"><a
href="(.*)"
target="_blank">(.*)</a></td>#iUs';
preg_match_all($p,$str,$ar);
print_r($ar[0]);
?>
$ar[0]
的所有值就是你想要的地址了
测试过
没问题

‘肆’ php解析出<a>标签中的“href”属性的值。

用正则取,例:
$str = '<A rel="nofollow" target="_blank" href=" http://m.tsci.com.cn/iPhone" class="see-all">';
preg_match("/href=\"(.*)\" /", $str, $a);
print_r($a);
echo $a[1];

‘伍’ php获取html标签内容

$pattern='#<ahref="([^"]*?)"title="([^"]*?)"#i';

$str='上面的标签内容';

if(preg_match($pattern,$str,$match)){
var_mp($match[1],$match[2]);
}else{
//匹配失败
}

‘陆’ 用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 遍历来页面上的 <a>标签 取出href值

去搞个正则,匹配,就弄个匹配任意URL的正则,这个估计都能直接搜索到。这样都不用遍历了。

‘捌’ php正则获取href的链接

使用正则中的子模式,按给出的代码匹配的话大概是这样

$pattern='/href="([^(}>)]+)"/';

然后使用preg_match或者preg_match_all如果替换的话使用preg_replace即可

‘玖’ PHP网页中获取 href 属性中跟在问号后面的部分.

说白了这就是获取的GET方法传来的参数而已~
举个栗子
a.php
<a href="b.php?new=<?php echo '123456'; ?>">点我传值</a>

b.php
<?php
$b=$_GET['new'];
echo '传过来的值是'.$b;
?>

热点内容
郝斌数据库 发布:2025-02-06 22:44:57 浏览:181
全息存储器 发布:2025-02-06 22:43:51 浏览:116
游戏源码如何使用 发布:2025-02-06 22:43:40 浏览:713
表与数据库 发布:2025-02-06 22:42:47 浏览:438
典型宣传短片拍摄脚本 发布:2025-02-06 22:33:27 浏览:551
php数据库配置 发布:2025-02-06 22:29:38 浏览:17
android把 发布:2025-02-06 22:24:18 浏览:138
如何替换服务器上的图片 发布:2025-02-06 22:19:33 浏览:677
怎么翻录加密视频 发布:2025-02-06 21:58:12 浏览:552
逃离塔科夫启动器选什么服务器 发布:2025-02-06 21:44:48 浏览:294