php获取链接herf和文本(如果它们包含设置文本)


php get link herf and text if they contain set text

如何从类似的链接中获取herf链接和文本

    <a herf="google.com">boom</a>

我只需要google.com的部分和boom文本?

此外,我如何过滤掉链接,以确保我只得到带有文本框的链接的herf,因为页面上有类似的链接

    <a herf="google.com">boom</a>
    <a herf="google.com">boom1</a>
    <a herf="google.com">boom2</a>
    <a herf="google.com">boom3</a>

尝试使用.filter()及其回调功能来满足您的需求,

var anchorWithSpecificText = $('a').filter(function(){
  return $(this).text() == "boom";
});

演示

不知道如何获得它们,但这将在php上完成任务http://sandbox.onlinephpfunctions.com/code/3920bf99f02b18bc707d2699a2e37ab25879bb20

编辑:

<?php
$str = ' <a herf="google.com">boom</a>
    <a herf="google.com">boom1</a>
    <a herf="google2.com">boom</a>
    <a herf="google.com">boom3</a>';

preg_match_all('/'<a's[href]+'='"([a-zA-Z0-9'.'-'_'?'='#'&]+)'"'>boom'</ui',$str,$matches);
var_dump($matches[1]);