2013-03-05 3 views
0

나는 모든 스타일을 포함하는 배열을 가지고 있으며 PHP로 반복하여 적절한 CSS로 변경해야합니다. 이 같이 들어 예. 일반 CSS로 스타일 배열

,

Array 
(
    [#outlook a] => Array 
     (
      [padding] => Array 
       (
        [0] => 0 
       ) 

     ) 

    [body] => Array 
     (
      [width] => Array 
       (
        [0] => 100% !important 
       ) 

      [-webkit-text-size-adjust] => Array 
       (
        [0] => none 
       ) 

      [margin] => Array 
       (
        [0] => 0 
       ) 

      [padding] => Array 
       (
        [0] => 0 
       ) 

      [background-color] => Array 
       (
        [0] => #FAFAFA 
       ) 

     ) 
[.preheaderContent div a] => Array 
    (
     [color] => Array 
      (
       [0] => #336699 
      ) 

     [font-weight] => Array 
      (
       [0] => normal 
      ) 

     [text-decoration] => Array 
      (
       [0] => underline 
      ) 

    ) 

[.preheaderContent div a:visited] => Array 
    (
     [color] => Array 
      (
       [0] => #336699 
      ) 

     [font-weight] => Array 
      (
       [0] => normal 
      ) 

     [text-decoration] => Array 
      (
       [0] => underline 
      ) 

    ) 

) 

내가 모든 스타일 정보를 포함하는 큰 배열을해야합니다. 그래서 이것을 적절한 CSS로 변환해야합니다. 나는 이것이 아주 간단하다는 것을 안다. 하지만 어딘가 재귀 루프에 실패하고 있습니다. 이것은 내가 이것을 위해 사용하는 함수이다.

function cssbuild(&$cssArray) 
{ 
    foreach ($cssArray as $selector => $style) 
    { 
     if(is_array($style)) 
     { 
      return $this->cssbuild($style); 
     } 
     else 
     { 
      $cssArray[$selector] = $cssArray[$selector].":".$style.";"; 
     } 
    } 
} 
이 작업을 수행하는 방법에 어떤 생각이 크게 감상 할 수

... 당신은 주어진 예에는 재귀가없는

+1

루프의 코드는 어디에 있습니까? – DonCallisto

답변

2

이 시도 :

function createCSS($cssArray) 
{ 
    $css = ''; 
    foreach ($cssArray as $classname => $properties) 
    { 
     $css .= "$classname{"; 
     foreach((array) $properties as $propertyname => $propertyvalue) 
     $css .= $propertyname .": ".$propertyvalue[0].";"; 
     $css .= "}"; 
    } 
    return $css; 
} 
0

...

당신은 재귀

이 뭔가를 할 수
<?php 
BuildList($arrayParent, 0); 

function BuildList($arrayElements, $depth) 
{ 
    foreach($arrayElements as $element => $style) 
    { 
     echo str_repeat("&nbsp;&nbsp;", $depth) . $element . ":" . $style; 
     $depth++; 
     if(count($element->subCSSElement) > 0) 
      $depth = BuildList($element->subCSSElement, $depth); 

     return $depth; 
    } 
} 
?> 
+0

재귀를 지금 확인하십시오 ... – Stranger

+0

$ 스타일 또한 배열이 될 것이므로 오류가 반환됩니다 ... – Stranger