Solved

Parse text and create HTML links where appropriate

Posted on 2004-04-19
8
768 Views
Last Modified: 2009-12-16
I am looking for the following stored procedure:

  CREATE PROCEDURE spActivateLinks

     @text varchar(8000)

  AS
     
       -- all code would go here


  GO



-------------------

I simply want it to activate any potential HTML links that are contained in the text passed to it.
The following text would be parsed and converted to a link:


  * External sites - "http://", "news://", "ftp://" etc etc
  * Local Links - "/news" or "/news/" etc etc

-----------------

Alternatively, this can be achieved in C# but I would prefer it in SQL.
  *
0
Comment
Question by:smacca
8 Comments
 

Author Comment

by:smacca
ID: 10859017
I noticed that Expert Exchange already do exactly what I want to:

  * Notice how the "http://" and "ftp://" have been made into links.

That is EXACTLY what I want to achieve.

Cheers.
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10859073
Does you text already have some html tags
like
<HTML>
<BODY>
your text here
</BODY>
</HTML>

??

Could you post a sample text for us to work on ?

Hilaire
0
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 200 total points
ID: 10859116
If you are in a.Net environment, I'm sure this could be achieved very easily using regular expressions in your C# app.
Using merely 2-3 lines of code.
Maybe you should give it a try ?

Hilaire
0
 
LVL 3

Expert Comment

by:jayrod
ID: 10859302
I agree with hilaire here. I'm sure it would be possible to do some sort of string replacement. however the problem is that it would be much more effecient and easier to use a language that supports reg expressions
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 34

Expert Comment

by:arbert
ID: 10859334
I agree with the above.  It's not totally clear what you're working with, but usually it's the client application that decides if a link is encoded as an HREF--not the database app....
0
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 200 total points
ID: 10859915
here's a link to single lined function that should do the job

http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=423

I guess you'll manage to update the code so that it handles FTP urls too ...

Hilaire
0
 
LVL 5

Accepted Solution

by:
a1x earned 300 total points
ID: 10860792
You can use SQL server string functions to do what you want.  It is tedious and verbose compared to regular expressions, but it can be done.

Here is a sample that will create a link:

DECLARE @text varchar(4000)

SET @text = 'Turn http://www.yahoo.com into a hyperlink'

DECLARE @StartIndex smallint
DECLARE @EndIndex smallint
DECLARE @URL varchar(4000)

SET @StartIndex = charindex('http:', @text)
SET @EndIndex = charindex(' ', @text, @StartIndex)
SET @URL = substring(@text, @StartIndex, @EndIndex - @StartIndex)

SELECT STUFF(@text, @StartIndex, @EndIndex - @StartIndex, '<a href="' + @URL + '">' + @URL + '</a>')

The sample is very limited.  It only handles one reference in the string.  You would have to add indexes to handle multiple instances of http in the string.  Also, it assumes that the reference ends with space, which may not be the case.  
0
 

Expert Comment

by:Mustangz
ID: 12381131
I was wondering, does anyone know how to do this in ASP?
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now