MHF
MHF

Reputation: 527

how to search html content?

in my website user can add HTML content with WYSIWYG control . and i save these content to database .
i want to have a search on these data so i use this query :

select * from htmlcontent where content like '%' + @searchValue + '%'

but for example when user search "<p>" this query return all rows in my table . but i want user only can search on the html content (data that user can seen on the browser ) not tags

how can i do it ?

Edited : i want user search html content not tags . some thing like search in the browser(ctrl + F)

Upvotes: 0

Views: 933

Answers (3)

Greig
Greig

Reputation: 111

Why not modify the seach string on the way in so that it strips html tags there. Then check that the string is not empty before your search.

So a search string like <p>Hello</p> becomes just Hello

Upvotes: 0

Dervall
Dervall

Reputation: 5744

You need to remove all the HTML tags from the users input string, then search using the cleaned string. You might want to replace all found tags with % in order to match when tags are found within the content. For information on how to remove tag from the input string, see this question

Another alternative is to clean the WYSIWYG string, then search that. Neither of these two can be performed in the database without major string trickery. You are better off solving this on the ASP side.

Upvotes: 1

atoMerz
atoMerz

Reputation: 7672

I'm not sure but I think you can use TrimStart('<p>') and TrimEnd('</p>') on the results to get what you want.

Upvotes: 0

Related Questions