Express I recently developed an online forum program for a client, and I want to display the URL or e-mail address in the user's statement with a hyperlink. The regular expressions with JavaScript is the easiest to implement.
Users enter their speeches in a multiline text box in the form, and then send the message to the Forum's user address area, however, before displaying the message in the forum, I'll call a function to process the message and move the URL.
I don't want to discuss here how to get a record out of the database, this site has been very thorough. We assume that the user's message text is stored in the database and given a variable called S_message.
<%
' ... start the page and spit out HTML to the browser
"Call" function to convert the message
Response.Write to_html (S_message)
1. Convert quotes to "such HTML elements." It's not necessary, but it's best to do so.
2. Convert the less than number to HTML element. In this case, if someone in the message sent to use less than
Number, HTML will output correctly. In addition, it also prevents some people from playing tricks, such as the use of <b>bold</b> to specific words in bold display.
3. Convert the greater-than number to. Reasons above.
4. Convert the return line to the HTML line-wrapping label.
"
5. This is what we want to move. It allows people to put simple HTML in the code and escape the code conversion. However, they have to use "/" to circumvent the "<>" code check. I think someone will find a way around the code conversion, and if they do, it would be more appropriate to use the word "cow" to describe their level.
6. Finally, invoke the Edit_hrefs function of JavaScript.
Now, let's take a look at what each line of JavaScript functions does:
1. Create a string object for the parameters that pass the function.
2. Put all the http://www. [Something] Find out and convert into http:////?¤?
[Something]. This is a temporary measure to deal with all the www. [Something]. So
http://www.pinarello.com/is replaced with http://?¤?.pinarello.com/.
3. Conversion of the remaining http://[something], some URLs are not started with www. Like what
http://uk.imdb.com/will be converted to <a
href= "http://uk.imdb.com/" >http://uk.imdb.com/</a>
4. Find All www. [Something], convert them to HTML. For example, www.principia.dk will be converted into <a href= "http://www.principia.dk" >www.principia.dk</a>
5. Put all the http://?¤ in the second part? [something]/to change back. http://in the second step?
¤?.pinarello.com/will be converted to http://www.pinarello.com/.
6. Finally, find the e-mail address to convert it to <a href= "Mailto:[e-mail addresses" >[e-
Mail address]</a>. The regular expression I use to find e-mail addresses is different from
Ian stalling, but I haven't found any e-mail addresses that can't be handled in this way. However, it has not been thoroughly tested. Whenever you find any problems, it's best to replace the code I wrote with Ian's code right away.
You can use this function for any purpose. You might be able to enhance its functionality, or delete unwanted items, or add new functions. If you do, you jiangle in it!
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