Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove html tags from a column

I have the a column in my table which stores a paragraph like below :

<p>I like it.</p>this is my job.<main>current.</main>

I want to remove the tags <p>, </p>, and and all tags between < and >. So my expected output will be like below :

I like it. this is my job. current.

1 Answers

please try this

DECLARE @txt NVARCHAR(MAX) = '<p>I like it.</p>this is my job.<main>current.</main>'

SELECT x.value('.', 'NVARCHAR(MAX)') FROM ( SELECT x = 
CAST(REPLACE(REPLACE(@txt, '>', '/>'), '</', '<') AS XML) ) r

this will help to remove all tags

like image 123
samir Avatar answered Sep 05 '25 05:09

samir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!