Strip p tags from an array element

I have a bit of code below, but unfortunately some of the elements in the second part of the array come with p tags already attached. So wondered if there was a way of stripping those p tags before it is displayed on the page.

<%
OpenDB
sSQL = "SELECT * FROM products ORDER BY PID DESC LIMIT 10"
OpenRS(sSQL)
arr = rs.GetRows()
For i = 0 To UBound(arr,2)
wr "<p style='color:#ffffff; text-decoration:underline; line-height:18px; width:540px;'>" & arr(1,i) & "</p>"
wr "<p style='color:#ffffff; font-size:13px; width:530px;'>" & arr(2,i) & "</p>"
wr "<div style='position:relative; width:1005; height:6px; clear:both'></div>"
Next
CloseRS
CloseDB
%>

If it’s just wrapped in paragraphs, you can use Replace

arr(1,i).ToString().Replace("<p>", "").Replace("</p>", "")

If it’s anything more complex (like inline css - bad developer! :stuck_out_tongue:) , you’ll need to use a regular expression

Hi Dave,
Thanks for getting back to me.

Added the line of code in and got an error -

<%
OpenDB
sSQL = "SELECT * FROM products WHERE (Status!='SOLD') ORDER BY PID DESC LIMIT 10"
OpenRS(sSQL)
arr = rs.GetRows()
For i = 0 To UBound(arr,2)
wr "<p style='color:#ffffff; text-decoration:underline; line-height:12px; width:550px;'><a href='/product/" & arr(12,i) & "' style='color:#ffffff' title='"& arr(9,i) &"'>" & arr(1,i) & "</a></p>"
wr "<p style='color:#ffffff; font-size:13px; width:540px;'>" & arr(2,i).ToString().Replace("<p>", "").Replace("</p>", "") & "</p>"
wr "<div style='position:relative; width:100%; height:2px; clear:both'></div>"
Next
CloseRS
CloseDB
%>

As below right at the bottom -

http://www.pendulumofmayfair.co.uk/default2.asp

Sorry, should have caught it was classic asp, not .net

You’ll need to use this format instead:

replace(replace(arr(2,1), "</p>", ""), "<p>", "")
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.