$mesg[$i] = eregi_replace("$mesg[$i]","[<a href=\"mailto:$mesg[$i]\">$mesg[$i]</a>]",$mesg[$i]);

解决方案 »

  1.   

    那如果用正则表达式验证http://的地址?
      

  2.   

    http://www.foresight.com.hk/bbs
    asp 版
    必须http://开头,以空格或回车还行结束,如果出现,()将会出现错误的连接。
    Function setLink(str)
      '$ID:2002-6-24 10:10 
      '@Function: set string "http://" to link
      '@Ver1.0
      '@Author:[email protected]
      
       setLink=str
    setLink=replace(setLink,"HTTP://","http://")
    setLink=replace(setLink,"&nbsp;"," ")
    setLink=replace(setLink,chr(13),"<br>")
    setLink=replace(setLink,"&lt;br&gt","<br>")
    setLink=replace(setLink,"&lt;BR&gt","<br>")
    setLink=replace(setLink,"''",chr(39))
       intDeal= instr(setLink,"http://")

    if intDeal<=0 then 
    exit function
    end if
    'get first space after intDeal

    args=split(setLink,"http")
    buf=""
    for i=0 to Ubound(args)

      if (left(args(i),3)<>"://" )  then
    buf=buf&args(i) 'store 偶数
    else 
    linktmp=args(i)
    strlink=linktmp
    nbsp="" 
    intSpace=instr(linktmp," ")
    intBr=instr(linktmp,"<br>")
    if intSpace>intBr then intSpace=intBr
    if intSpace>0 then 
    strlink=trim(left(linktmp,intSpace-1))
    nbsp=mid(linktmp,intSpace)
    end if
    strlink="http"&strlink
    strlink="<a href="""&strlink&""" target=_blank>"&strlink&"</a>"&nbsp

    buf=buf&strlink 'store link
    end if
    next

    setLink=buf
      End Function
      

  3.   

    Function setLink(str)
      '$ID:2002-6-27 17:39 
      '@Function: set string "http://" to link
      '@Ver1.1
      '@Author:[email protected]
      'Fix ']) '&FullSpace ,etc. 
       setLink=str
    setLink=replace(setLink,"HTTP://","http://")
    setLink=replace(setLink,"&nbsp;"," ")
    setLink=replace(setLink,chr(13),"<br>")
    setLink=replace(setLink,"&lt;br&gt","<br>")
    setLink=replace(setLink,"&lt;BR&gt","<br>")
    setLink=replace(setLink,"''",chr(39))
       intDeal= instr(setLink,"http://")

    if intDeal<=0 then 
    exit function
    end if
    'get first space after intDeal

    args=split(setLink,"http")
    buf=""
    for i=0 to Ubound(args)

      if (left(args(i),3)<>"://" )  then
    buf=buf&args(i) 'store 偶数
    else 
    linktmp=args(i)
    strlink=linktmp
    nbsp="" 
    intSpace=instr(linktmp," ")
    intBr=instr(linktmp,"<br>")
    if intSpace>intBr then intSpace=intBr

    intUnKnow=instr(linktmp,"。")
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp,")")
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp,",")
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp,"]")
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp," ") '中文半角空格
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp," ")'中文全角空格
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp,"(")
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    intUnKnow=instr(linktmp,")")
    if intSpace>intUnKnow and intUnKnow<>0 then intSpace=intUnKnow
    if intSpace>0 then 
    strlink=trim(left(linktmp,intSpace-1))
    nbsp=mid(linktmp,intSpace)
    end if
    strlink="http"&strlink
    strlink="<a href="""&strlink&""" target=_blank>"&strlink&"</a>"&nbsp

    buf=buf&strlink 'store link
    end if
    next

    setLink=buf
      End Function