Re: Function To Strip HTML

From: "Ozer, Pam" <pozer(at)automotive(dot)com>
To: "Ozer, Pam" <pozer(at)automotive(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function To Strip HTML
Date: 2011-02-24 00:17:50
Message-ID: 216FFB77CBFAEE4B8EE4DF0A939FF1D14F84CA@mail-001.corp.automotive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I found a way to do this using regular expressions. Found this on
another website

CREATE OR REPLACE FUNCTION strip_tags(TEXT) RETURNS TEXT AS $$
2 SELECT regexp_replace(regexp_replace($1, E'(?x)<[^>]*?(\s alt \s* =
\s* ([\'"]) ([^>]*?) \2) [^>]*? >', E'\3'), E'(?x)(< [^>]*? >)', '',
'g')
3$$ LANGUAGE SQL;

From: pgsql-sql-owner(at)postgresql(dot)org
[mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Ozer, Pam
Sent: Wednesday, February 23, 2011 3:41 PM
To: pgsql-sql(at)postgresql(dot)org
Subject: [SQL] Function To Strip HTML

I have the following function that I used in MSSQL. I would like to
create the same function in PostgreSql. I think I am a bit confused on
how to create and set variables in PostgreSql. Can someone give me a
place to start to create something like this?

Thanks

Pam

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE FUNCTION [dbo].[udf_StripHTML]

(@HTMLText VARCHAR(MAX))

RETURNS VARCHAR(MAX)

AS

BEGIN

DECLARE @Start INT

DECLARE @End INT

DECLARE @Length INT

SET @Start = CHARINDEX('<',@HTMLText)

SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))

SET @Length = (@End - @Start) + 1

WHILE @Start > 0

AND @End > 0

AND @Length > 0

BEGIN

SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')

SET @Start = CHARINDEX('<',@HTMLText)

SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))

SET @Length = (@End - @Start) + 1

END

RETURN LTRIM(RTRIM(@HTMLText))

END

GO

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Piotr Czekalski 2011-02-24 09:18:22 Re: Compare two Data bases Structure
Previous Message Plugge, Joe R. 2011-02-24 00:09:09 Re: Compare two Data bases Structure