English 中文(简体)
在网页上找到链接,并通过海关职能加以管理
原标题:Find links in page and run it through custom function
  • 时间:2011-10-03 01:44:05
  •  标签:
  • php
  • regex
  • url
function link_it($text)
{
    $text= preg_replace("/(^|[
 ])([w]*?)((ht|f)tp(s)?://[w]+[^ ,"

	<]*)/is", "$1$2<a href="$3" target="_blank">$3</a>", $text);  
    $text= preg_replace("/(^|[
 ])([w]*?)((www|ftp).[^ ,"	

<]*)/is", "$1$2<a href="http://$3" target="_blank">$3</a>", $text);  
    $text= preg_replace("/(^|[
 ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+)+)/i", "$1<a href="mailto:$2@$3" target="_blank">$2@$3</a>", $text);  
    return($text);  
}

这符合工作守则。

Im 从事新职能

function shorturl2full($url)
{
    echo  URL IS:   . $url;
    return "FULLLINK";
}

想法是取回ur并回。 稍后将努力将其改为全程。 因此,如<代码>t.co,将全程浏览。

$text= preg_replace("/(^|[
 ])([w]*?)((ht|f)tp(s)?://[w]+[^ ,"

	<]*)/is", "$1$2<a href="$3" target="_blank">" .  shorturl2full("$3") . "</a>", $text);  
        $text= preg_replace("/(^|[
 ])([w]*?)((www|ftp).[^ ,"	

<]*)/is", "$1$2<a href="http://$3" target="_blank">" .  shorturl2full("$3") . "</a>", $text);  
        $text= preg_replace("/(^|[
 ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+)+)/i", "$1<a href="mailto:$2@$3" target="_blank">$2@$3</a>", $text);  
        return($text);  
}

难道我不胜诉。

因此,如果你点击该链接,就应当使用原样,但你看到的是<代码>shorturl2full的产出。

So like <a href="t.co">FULLLINK</a>

我想试图写一下<代码>shorturl2full,我自己认为,我对如何做到这一点有着非常大的想法。 问题载于<代码>link_it功能...... 它需要通过该圆环,以显示它所恢复的内容。

最佳回答

http://nz.php。

function link_it($text)
{
    $text= preg_replace_callback("/(^|[
 ])([w]*?)((ht|f)tp(s)?://[w]+[^ ,"

	<]*)/is",   shorturl2full , $text);  
    $text= preg_replace_callback("/(^|[
 ])([w]*?)((www|ftp).[^ ,"	

<]*)/is",   shorturl2full , $text);  
    $text= preg_replace_callback("/(^|[
 ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+)+)/i",   shorturl2full , $text);  
    return($text);  
}

function shorturl2full($url)
{
    $fullLink =  FULLLINK ;
    // $url[0] is the complete match
    //... you code to find the full link
    return  <a href="  . $url[0] .  ">  . $fullLink .  </a> ;
}

希望这一帮助

问题回答




相关问题
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 ...

热门标签