Reputation: 830
My Code:
$css="
.class1{
padding:10px 15px 0 auto;
padding:10px 150px 0 20px;
padding:13px 30px 10px 50px;
padding:24px 1px 0 -20px;
}
";
Function below extracts content between [padding:] and [;]
function extract_unit($css, $start, $end){
$pos = stripos($css, $start);
$str = substr($css, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
echo $unit;
return $unit;
}
echo extract_unit($css , 'padding:',';');
Output: 10px 15px 0 auto
How can i extract all paddings in an array using this function.. So the result i need to be like this :
array(
"10px 15px 0 auto",
"10px 150px 0 20p",
"13px 30px 10px 50px",
"24px 1px 0 -20px"
);
Upvotes: 1
Views: 93
Reputation: 1048
You can use a regex for this
preg_match_all("/padding:(.*);/siU",$css,$output);
print_r($output[1]);
Upvotes: 3