I got this RegEx from another post, but it doesn’t fully function like it should.
Here is the pattern: /(<[^>]+ (height|width)=)"[^"]*"/gi and replacement: $1"auto"
Here is a typical replacement string:
<p width="123" height="345"></p>
Now, I would like this to return <p width="auto" height="auto"></p>, but instead it returns <p width="123" height="auto"></p>.
Could you help me figure out how you can replace both the width and height-values in an HTML-tag? Oh, and I would really like it to work with small apostroph-signs as well (e.g. width='*').
Thanks a lot!
Don’t do this with regex. Use the DOM instead — it’s not very hard:
It might be better simply to remove the attribute instead — if so, do
$el->removeAttribute('width');or the analogous operation onheight.