Solved

Parse text and create HTML links where appropriate

Posted on 2004-04-19
8
789 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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
 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql 2014,  lock limit 5 32
sql server computed columns 11 31
Help Required 3 97
SQL server vNext 18 29
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…
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.
Viewers will learn how the fundamental information of how to create a table.

773 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