当前位置:首页 » 编程语言 » 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;
?>

热点内容
sql临时表和表变量 发布:2025-05-17 06:02:38 浏览:723
苹果如何用安卓无线耳机 发布:2025-05-17 06:01:53 浏览:821
sqlserver表关系 发布:2025-05-17 06:01:02 浏览:996
2017途观配置什么音响 发布:2025-05-17 05:53:50 浏览:843
64位安装sql2000 发布:2025-05-17 05:33:17 浏览:845
安卓手机屏幕仪哪个好 发布:2025-05-17 05:33:16 浏览:592
加密的备忘录 发布:2025-05-17 05:32:30 浏览:743
企业应用锁初始密码多少 发布:2025-05-17 05:26:04 浏览:834
苹果和安卓怎么共享wifi 发布:2025-05-17 05:21:09 浏览:826
编程实例100篇 发布:2025-05-17 05:16:54 浏览:263