SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
Hybrid View
-
Jan 19, 2004, 06:32 #1
- Join Date
- Oct 2000
- Location
- Philadelphia, PA
- Posts
- 4,708
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
textbox to recognize url create link
I'm working on making a form that when submitted checks to see if the user has typed in a link, if so it converts it to a hyperlink. This is for a news submission form on one of my sites. I don't really care if it is a popup like SPF has, or not. Just wanted to see if anyone here has done something similiar, and which route they took. Thanks!
"Does this napkin smell like chloroform?"
...now with SnapFoo!
My Blog | My Twitter | My Company | SitePoint Podcast
*** Matt Mullenweg on the SitePoint Podcast ***
-
Jan 19, 2004, 08:31 #2
- Join Date
- May 2002
- Location
- Jacksonville, FL
- Posts
- 1,168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes...
Search this forum, as functions have been posted here pretty recently.
-
Jan 19, 2004, 08:39 #3
- Join Date
- May 2003
- Location
- Houston, TX
- Posts
- 138
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's a function that I use. I'm pretty sure I took it from a post here. Probably in the Funky Functions thread, but I haven't checked lately.
Code:Function LinkURLs(tempTxt) Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True 'Hyperlink Email Addresses regEx.Pattern = "([_.a-z0-9-]+@[_.a-z0-9-]+\.[a-z]{2,3})" tempTxt = regEx.Replace(tempTxt, "<a href=""mailto:$1"">$1</a>") 'Hyperlink URL's regEx.Pattern = "((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])" tempTxt = regEx.Replace(tempTxt, "<a href=""$1"" target = '_blank'>$1</a>") 'Make <a href="www = <a href="http://www tempTxt = Replace(tempTxt, "href=""www", "href=""http://www") LinkURLs = tempTxt End Function
I think sometimes I dream in code.
-
Jan 19, 2004, 08:45 #4
- Join Date
- Oct 2000
- Location
- Philadelphia, PA
- Posts
- 4,708
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Thanks Tank I'll give it a shot!
I did search with no results. Must have used the wrong keywords"Does this napkin smell like chloroform?"
...now with SnapFoo!
My Blog | My Twitter | My Company | SitePoint Podcast
*** Matt Mullenweg on the SitePoint Podcast ***
-
Jan 19, 2004, 08:45 #5
- Join Date
- Oct 2000
- Location
- Philadelphia, PA
- Posts
- 4,708
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You just wanted to hit 700!!!
"Does this napkin smell like chloroform?"
...now with SnapFoo!
My Blog | My Twitter | My Company | SitePoint Podcast
*** Matt Mullenweg on the SitePoint Podcast ***
-
Jan 19, 2004, 16:37 #6
- Join Date
- Jan 2004
- Location
- Dallas
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've got a whole PrepareText function that I use, and I used the function above in it, and it renders the text odd... before I used this function, the text rendered normally, like this:
http://www.fark.com
www.fark.com
fark.com
fakeaddress@yahoo.com
After this function, the text is rendered like this:
http://www.fark.com www.fark.com fark.com
fakeaddress@yahoo.com
===========================
I have never been good with regular expressions, is there anything in the above that would prevent the end line/line break from being converted properly to a <br> tag (that happens elsewhere in the function).
-
Jan 19, 2004, 19:48 #7
- Join Date
- May 2002
- Location
- Jacksonville, FL
- Posts
- 1,168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe I was imagining things. Lol, I can assure you that it wasn't for 700 posts though... but thanks for pointing that out.
Let me know how that function goes for you.
-
Jan 19, 2004, 20:06 #8
- Join Date
- Oct 2000
- Location
- Philadelphia, PA
- Posts
- 4,708
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
It worked perfect man. Exactly what I needed. Thanks!
"Does this napkin smell like chloroform?"
...now with SnapFoo!
My Blog | My Twitter | My Company | SitePoint Podcast
*** Matt Mullenweg on the SitePoint Podcast ***
-
Jan 20, 2004, 07:16 #9
- Join Date
- Oct 2000
- Location
- Philadelphia, PA
- Posts
- 4,708
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
That function does not work well with apostrophes ('). It also didn't like the "target='_blank'". I fixed both the errors:
Code:Function LinkURLs(tempTxt) Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True temptxt = replace(temptxt, "'", "''") 'Hyperlink Email Addresses regEx.Pattern = "([_.a-z0-9-]+@[_.a-z0-9-]+\.[a-z]{2,3})" tempTxt = regEx.Replace(tempTxt, "<a href=""mailto:$1"">$1</a>") 'Hyperlink URL's regEx.Pattern = "((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])" tempTxt = regEx.Replace(tempTxt, "<a href=""$1"" target=""_blank"">$1</a>") 'Make <a href="www = <a href="http://www tempTxt = Replace(tempTxt, "href=""www", "href=""http://www") LinkURLs = tempTxt End Function
"Does this napkin smell like chloroform?"
...now with SnapFoo!
My Blog | My Twitter | My Company | SitePoint Podcast
*** Matt Mullenweg on the SitePoint Podcast ***
-
Jan 21, 2004, 08:48 #10
- Join Date
- May 2003
- Location
- Houston, TX
- Posts
- 138
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I had not run across the apostrophy problem, but I have different functin created based if I want to target _blank or not. That's just my standard one.
Good job on the apostrophes. I'll have to add that in.I think sometimes I dream in code.
-
Jan 23, 2004, 15:54 #11
- Join Date
- Jun 2003
- Location
- ether
- Posts
- 4,497
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Ahem, a mod, if you please.
Code:Function LinkURLs(tempTxt, tgt) 'Prefix underscore(_) to tgt tgt = "_" & tgt 'If tgt is blank, set it to self. If Trim(tgt)="_" Then tgt = "_self" End If Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True temptxt = replace(temptxt, "'", "''") 'Hyperlink Email Addresses regEx.Pattern = "([_.a-z0-9-]+@[_.a-z0-9-]+\.[a-z]{2,3})" tempTxt = regEx.Replace(tempTxt, "<a href=""mailto:$1"">$1</a>") 'Hyperlink URL's regEx.Pattern = "((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])" tempTxt = regEx.Replace(tempTxt, "<a href=""$1"" target=" & tgt & ">$1</a>") 'Make <a href="www = <a href="http://www tempTxt = Replace(tempTxt, "href=""www", "href=""http://www") LinkURLs = tempTxt End Function
Our lives teach us who we are.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Me - Photo Blog - Personal Blog - Dev Blog
iG:Syntax Hiliter -- Colourize your code in WordPress!!
-
Jan 23, 2004, 21:45 #12
- Join Date
- Oct 2000
- Location
- Philadelphia, PA
- Posts
- 4,708
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
We should all just keeping adding to this function until it is the "perfect" function lol We could even market it out to large firms and sell it for thousands!!!
"Does this napkin smell like chloroform?"
...now with SnapFoo!
My Blog | My Twitter | My Company | SitePoint Podcast
*** Matt Mullenweg on the SitePoint Podcast ***
-
Jan 24, 2004, 12:05 #13
- Join Date
- Jun 2003
- Location
- ether
- Posts
- 4,497
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by williamsba
So in fit for that, here's another mod.
Another thing that I thought of & that was left in the previous mod. What if
we wanna target a frame rather than the window attribute. So here's another mod.
Code:Function LinkURLs(tempTxt, tgt, frm) 'Prefix underscore(_) to tgt if frm=0 or null If (CInt(frm)=0) OR (CInt(frm)="") Then tgt = "_" & tgt End If 'If tgt is blank, set it to self. If (Trim(tgt)="_") OR (Trim(tgt)="") Then tgt = "_self" End If Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True temptxt = replace(temptxt, "'", "''") 'Hyperlink Email Addresses regEx.Pattern = "([_.a-z0-9-]+@[_.a-z0-9-]+\.[a-z]{2,3})" tempTxt = regEx.Replace(tempTxt, "<a href=""mailto:$1"">$1</a>") 'Hyperlink URL's regEx.Pattern = "((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])" tempTxt = regEx.Replace(tempTxt, "<a href=""$1"" target=" & tgt & ">$1</a>") 'Make <a href="www = <a href="http://www tempTxt = Replace(tempTxt, "href=""www", "href=""http://www") LinkURLs = tempTxt End Function
another optional parameter added by name of frm. If this parameter is set to
any number but 0, it will not add an underscore(_) to the parameter tgt
which specifies the target name. So if its omitted, then also it will add
underscore(_).
So, if you wanna target a frame, just set frm to any number, better be 1 of
ease of things.
So there!! Any more mods are more than welcome.Our lives teach us who we are.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Me - Photo Blog - Personal Blog - Dev Blog
iG:Syntax Hiliter -- Colourize your code in WordPress!!
Bookmarks