Converting Links in a text file to anchor tags usable in your website
Saturday, January 9th, 2010
I recently answered a question about converting links in a text file, eg, www.softsmart.co.za to an anchor link that could be used in a website, eg, <a href=”http://www.softsmart.co.za”>http://www.softsmart.co.za</a>.
I decided that since I was such an open source evangelist, the best thing I could do was whip up a little application to do this:
Here is a brief synopsis of what it does (links at the bottom):
It takes a text file that has one link per line.
You can start the program in several ways (its a console program):
1) Just start it and it will ask you to type in the full path and name of the file (unless the file is in the same directory, then name alone should be fine)
2) You can start the program from a dos prompt followed by the name of the file in quotes, eg, c:\>UrlToAnchor.exe “C:\Folder 1\Folder 2\test.txt”
3) Easiest method is open the folder that has this exe, then in a different folder open the folder with your text file, then just drag the text file onto the program.
It will ask you 3 questions. These are related to what you want the resultant anchor text to look like:
1) Do you want a title tag? If ‘y’ then it will place the title=”eee” into the tag, using the domain name as the title
2) Do you want to use the title tag as the link text? If ‘y’ then the title tag is the link text, ie, what the user sees and clicks on
3) Do you want the links to open in a new window? If ‘y’ it adds the target=”_new”. This is nice if you are placing these links on your own site but you don’t want people to go out of your site.
I tested this on a very average machine (my laptop) with a file that had 200 000 dummy links. It ran that in just under 2 minutes.
Ok, here is the disclaimer…
1) I am giving this away for free, so there are no guarantees. However, if you need help or you want a feature added, mail me, I’d be more than happy to help. My time is very limited however so you may have to wait.
2) I know that its scary using free software from someone you don’t know, so I’ll make this opensource. You can download the program and run it, or you can download the source and check it out, modify it then compile it yourself. Although I haven’t tested this on Linux yet, I do try to stick to ANSI C++, so this should compile on both (Please post here if you want me to compile a Linux version).
What do I ask in return? If you want to make a comment on the blog, make it nice! If you do download the source and modify it (or post it on your own website), please respect 2 things:
1) Please post back to my blog to let us all benefit from the mods
2) Please keep my title info at the top of the source file (its only one file). You can add yours below!
Click here to download the exe for windows
Click here to download the source file