My code:
$css=".class1{
padding:1330px 2220px 0 auto;
padding:10px auto 0 20px;
padding:101px auto 0 200px;
}";
$search=self::extract_unit($css,"padding:",";");
extract_unit: this function extracts content between [padding:] and [;]
will return 1330px auto 0 2220px
$replace=self::resort_padding_margin($search);
resort_padding_margin: this function resorts the content
will return 1330px 2220px 0 auto
$css = str_replace($search, $replace, $css);
echo $css;
when i apply this code the result will show like this :
.class1{
padding:1330px auto 0 2220px;
padding:10px auto 0 20px;
padding:101px auto 0 200px;
}
So how can i use this method to apply all padding to be show like this
.class1{
padding:1330px auto 0 2220px;
padding:10px 20px 0 auto;
padding:101px 200px 0 auto;
}
For this to work, your
self::extract_unitmethod has to return an array, one item per occurrence ofpadding.Then your
self::resort_padding_marginshould accept the search array and return another array with the modifications. Alternatively, write a loop in your main code and store the results of each call to this method inside an array.When done, you can pass both arrays to
str_replace.Btw, a CSS should only have one
paddingdefinition. You have three, which is a bit strange 🙂