2014-01-23 1 views

답변

1

나는이 스크립트를 오랫동안 사용해 왔으며 훌륭하게 작동합니다. RegEx를 사용하여 문자열에서 URL을 찾습니다.

function create_links(strText) 
    strText = " " & strText 
    strText = ereg_replace(strText, "(^|[\n ])([\w]+?://[^ ,""\s<]*)", "$1<a href=""$2"" ref=""nofollow"">$2</a>") 
    strText = ereg_replace(strText, "(^|[\n ])((www|ftp)\.[^ ,""\s<]*)", "$1<a target=""_blank"" ref=""nofollow"" href=""http://$2"">$2</a>") 
    strText = ereg_replace(strText, "(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)", "$1<a href=""mailto:[email protected]$3"">[email protected]$3</a>") 
    strText = right(strText, len(strText)-1) 
    strText = Replace(strText,"." & chr(34) & ">",chr(34) & ">") 
    strText = Replace(strText,".)" & chr(34) & ">",chr(34) & ">") 
    create_links = strText 
end function 

function ereg_replace(strOriginalString, strPattern, strReplacement) 
    dim objRegExp : set objRegExp = new RegExp 
    objRegExp.Pattern = strPattern 
    objRegExp.IgnoreCase = True 
    objRegExp.Global = True 
    ereg_replace = objRegExp.replace(strOriginalString, strReplacement) 
    set objRegExp = nothing 
end function 

나는 몇 가지 변경을 만들었습니다,하지만 원래는 여기에 ... http://www.ipaste.org/Ycc

0
    를 방문하시기 바랍니다
  1. 텍스트에서 HTTP : // 또는 HTTPS : //의 위치/입구를 찾습니다. "InStr"기능을 참조하십시오.
  2. URL의 끝 위치를 찾으면 SPACE char 또는 ";"과 같은 다른 문자가 될 수 있습니다. (제공하는 샘플에는 유효하지 않은 공백 문자).
  3. 일단 URL을 얻으면 HTML 태그 안에 넣습니다. Replace을 사용하거나 문자열을 연결하여이 작업을 수행 할 수 있습니다.
+0

제 1 부와 제 3 부 명확하고 아무 문제입니다. 그러나 howto는 효과적인 방법으로 Part 2를 수행합니까? – user1136199

관련 문제