?
Solved

Parse text and create HTML links where appropriate

Posted on 2004-04-19
8
Medium Priority
?
813 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 600 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

770 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