Two functions that replace the keyword of an article with a hyperlink

Source: Internet
Author: User

In some casesArticleThe website link in the content must be automatically converted into a hyperlink for certain settings.

Assume that the content of the article is "HTML needs to be filtered in many casesCodeOnly plain text is displayed. The following function can be used to achieve the effect ." The "filter", "html", and "function" must be automatically set as hyperlinks to achieve this effect. "In many cases, HTML code in the content must be filtered to only display plain text, use the following function to achieve the effect."

For intra-site search, you can use the first function to perform full-site search. If you refer to different URLs, you can use the second function. The Code is as follows:

Code1:
Function linkstr (STR) <br/> dim str_1, str_2, str_3, str_4 <br/> str_1 = "filter, HTML, function" <br/> str_2 = Split (str_1, ",") <br/> for each str_3 in str_2 <br/> If Len (str_4) = 0 then <br/> str_4 = Replace (str_4, str_3, "<a href =" http://www.wuhane.com/tech? Key = "mce_href =" http://www.wuhane.com/tech? Key = "" & str_3 & ">" & str_3 & "</a>") <br/> next <br/> linkstr = str_4 <br/> end Function

 

Code2:
Function linkstr (STR) <br/> dim str_1, str_2, str_3, str_4, str_5, str_6 <br/> str_1 = "filter -1.htm,html-2.htm,#-3.htm" <br/> str_2 = Split (str_1, ",") <br/> for each str_3 in str_2 <br/> str_5 = mid (str_3, (instr (str_3, "-") + 1 )) <br/> str_6 = Replace (str_3, ("-" & str_5), "") <br/> If Len (str_4) = 0 then <br/> str_4 = STR <br/> end if <br/> str_4 = Replace (str_4, str_6, "<a href =" & str_5 & "mce_href =" & str_5 & ">" & str_6 & "</a> ") <br/> next <br/> linkstr = str_4 <br/> end Function

Use the following code to test function reference on the page:
Content = "in many cases, HTML code in the content needs to be filtered out, only plain text is displayed, and the following function can be used to achieve the effect. "</P> <p> response. Write linkstr (content) <br/>

in variable str_1, multiple keywords are separated by the comma, in code2, use the "-" interval between keywords and URLs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.