Reputation: 7256
I have absoulutely no experience with regular expressions, so I've run into a small issue.
I need to replace all height="*"
and width="*"
-html-tags with height="auto"
and width="auto"
.
What regular expression can I use to accomplish this in PHP?
Thanks!
Upvotes: 0
Views: 253
Reputation: 20343
Note that this is only true for the literal asterisk character. For wildcards you should the regex after the update.
You don't need regular expressions for this, just two str_replace()
$html = str_replace (' height="*"', ' height="auto"', $html);
$html = str_replace (' width="*"', ' width="auto"', $html);
Update
You can use RegEx though. It requires more resources, but some rudamentary checks can be added (so for example height="*"
won't be changed when NOT inside an element):
preg_replace ('/(<[^>]+ (height|width)=)"[^"]*"/i', '$1"auto"', $html);
Upvotes: 2