问题
I have CSS code where I want to find Padding -or- Margin Properties
(where it has 4 values) and to switch the left value with right value:
e.g. padding: 1px 2px 3px 4px;
- to be like this -padding: 1px 4px 3px 2px;
How can I achieve this with regex & PHP? :-)
回答1:
Try this:
preg_replace(
'/padding:\s*?(\d*px)\s*(\d*px)\s*(\d*px)\s*(\d*px)\s*?;/i',
'padding: $1 $4 $3 $2;',
$css
);
Explanation
\s matches a space
\d matches a digit
\d*px will match any digits followed by a 'px'
来源:https://stackoverflow.com/questions/13191473/css-regex-switching-values-of-padding-or-margin-property