需要一个简单的preg_match,它将在内容中找到“ c.aspx”(不带引号),如果找到,它将返回整个url.举个例子
$content = '
';
现在它应该从$content进行preg_match“ c.aspx”并给出如下输出
"/m/c.aspx?mt=01_9310ba801f1255e02e411d8a7ed53ef95235165ee4fb0226f9644d439c11039f%7c8acc31aea5ad3998&n=783622212"
$content除“ c.aspx”外应具有更多链接.我不要我只想要所有具有“ c.aspx”的网址.
请让我知道我该怎么做.
解决方法:
您使用DOM解析HTML,而不是正则表达式.您可以使用正则表达式来解析属性值.
编辑:更新示例,以便检查c.aspx.
$content = '
';
$dom = new DOMDocument();
$dom->loadHTML($content);
$anchors = $dom->getElementsByTagName('a');
if ( count($anchors->length) > 0 ) {
foreach ( $anchors as $anchor ) {
if ( $anchor->hasAttribute('href') ) {
$link = $anchor->getAttribute('href');
if ( strpos( $link, 'c.aspx') ) {
echo $link;
}
}
}
}
标签:php,dom,regex,preg-match
来源: https://codeday.me/bug/20191012/1902601.html