当前位置:首页 » 编程语言 » 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-07-05 16:10:30 浏览:529
微博数据库设计 发布:2025-07-05 15:30:55 浏览:26
linux485 发布:2025-07-05 14:38:28 浏览:306
php用的软件 发布:2025-07-05 14:06:22 浏览:757
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:433
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:709
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:244
java的开发流程 发布:2025-07-05 12:45:11 浏览:689
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:286
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:835