当前位置:首页 » 编程语言 » 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-03-26 02:00:46 浏览:546
华为荣耀登录密码是多少 发布:2025-03-26 02:00:44 浏览:257
androiddimens 发布:2025-03-26 01:37:00 浏览:472
电视出现认证服务器无响应怎么办 发布:2025-03-26 01:33:21 浏览:686
linux安装mysql55 发布:2025-03-26 01:31:10 浏览:759
如何远程登录家里的服务器 发布:2025-03-26 01:10:49 浏览:763
河北长城dns服务器地址 发布:2025-03-26 01:07:05 浏览:838
社保的卡银行密码是多少 发布:2025-03-26 01:00:28 浏览:975
买手机如何看是正品安卓 发布:2025-03-26 00:28:25 浏览:363
对象没有存储类型 发布:2025-03-26 00:10:03 浏览:402