English 中文(简体)
如何从网页上删除重复链接,但第一页除外。
原标题:How do i remove duplicate links from a page except first

我对一些内容存在问题,这些内容又一次有同样的联系,因此,除单一内容外,想要消除所有重复联系,谁会想如何这样做?

here is my code which remove all links

function anchor_remover($page) {
    $filter_text = preg_replace("|<<blink>a *<blink>href=<blink>"(.*)">(.*)</a>|","\2",$page); 
    return $filter_text; 
}

add_filter( the_content ,  anchor_remover );

基本上需要文字压缩、过滤内容和消除重复链接,这只能有一个单一链接。

最佳回答

采用预先选择:

<?php
/*
 * vim: ts=4 sw=4 fdm=marker noet
 */
$page = file_get_contents( ./dupes.html );

function do_strip_link($matches)
{
        static $seen = array();

        if( in_array($matches[1], $seen) )
        {
                return $matches[2];
        }
        else
        {
                $seen[] = $matches[1];
                return $matches[0];
        }
}
function strip_dupe_links($page)
{
        return preg_replace_callback(
                 |<as+href="(.*?)">(.*?)</a>| ,
                do_strip_link,
                $page
        );
}

$page = strip_dupe_links($page);
echo $page;

投入:

<html>
        <head><title>Hi!</title></head>
        <body>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="foo.html">foo</a>
                <a href="bar.html">bar</a>
        </body>
</html>

产出:

<html>
        <head><title>Hi!</title></head>
        <body>
                <a href="foo.html">foo</a>
                foo
                foo
                foo
                foo
                foo
                foo
                foo
                foo
                foo
                <a href="bar.html">bar</a>
        </body>
</html>
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签