Regex to remove id attributes from HTML

I have html with a lot of attributes id="something".

All html is inside $datavar.

Trying to remove all id="*"from $data:

$data = preg_replace('\<id="[*]"^\>', '', $data);

Doesn't work, what's wrong?

+5
source share
4 answers

Try this instead:

$data = preg_replace('#\s(id|class)="[^"]+"#', '', $data);

Note. We solved the remaining problems in the chat. The answer still matches the problem described in the question.

+10
source

try the following:

'id="[^"]*"'
+4
source
$data = preg_replace('#<id=".*?"/>#', '', $data); 
0
$data = preg_replace('/(<([^>]*))(id=("[^"]*"|[^" >]*))/', '$1', $data); 

id = foo ( ") id =

0

All Articles