Reputation: 43617
I have an html with a lot of id="something"
attributes.
All the html is inside $data
var.
Trying to remove all the id="*"
from $data
:
$data = preg_replace('\<id="[*]"^\>', '', $data);
Doesn't work, whats wrong?
Upvotes: 6
Views: 9867
Reputation: 339
$data = preg_replace('/(<([^>]*))(id=("[^"]*"|[^" >]*))/', '$1', $data);
it eliminate also id=foo (without ") in tag and keep id= out of tag
Upvotes: 0
Reputation: 9311
Try this instead:
$data = preg_replace('#\s(id|class)="[^"]+"#', '', $data);
Note: We solved the remaining issues in chat. The answer still fits the problem described in the question.
Upvotes: 16