Regex strip all html tags excluding & &

I'm relatively new to regex, but my goal is to remove all html tags from the string, excluding the tags <br>and <a>using class = user. I want a custom this regular expression to clear the unnecessary html garbage from the contentedittable fields.

Hope one of your regex masters can help ...

Here is a test example: http://gskinner.com/RegExr/?2tpai

I think I'm close, but the class = end tag is currently selected as garbage when it is needed.

+3
source share
3 answers

I would suggest you this:

<(?!a class='user'|br|/a)[^>]+>

i.e, html </a>, .

, , <a class='user', <...

, html , - , , <a class='user'..../a> s, , , <a class='user'..../a> .

+3

HTML , HTML . . , XML HTML ? - .

, , "" "" , , . SQL ; , , , - .

HTML , <br> <a> DOM. ( , , , !). , , , JS , DOM, , .

JavaScript DOM, , quirksmode intro .

+5

:

<?php
$new_content = strip_tags($content, '<a><br>');

This will allow the use of all brand all aelements. Directly in this function, you do not have the ability to enable / disable element properties, such as class="user". This function always allows / prohibits specified elements with all properties.

-1
source

All Articles