2017-02-28 5 views
-1

私は次の機能を持っています。これは、WordPress関数によく似た、PHPでスタイルをエンキューするためのものです。PHPの文字列で改行が機能しない

public function printHTML() { 
     foreach($this->styles as $style) { 
      $style = sprintf('<link href="%s" rel="stylesheet" type="text/css" />\n', $style); 
      $this->print_html .= $style; 
     } 
     return $this->print_html; 
} 

そして、私ののindex.phpページ内でこれを呼び出すときに、私は次の操作を行います

echo nl2br($styles->printHTML()); 

しかし、単に内醜い1つのラインに全体print_htmlをスローするように見えますソース、私はここで間違って何をしているかについての任意のアイデア?

答えて

2

\nだけあなたがスターだ、二重引用符で囲まれた文字列、すなわちエコー"\n";またはあなたのケースで

$style = sprintf("<link href='%s' rel='stylesheet' type='text/css' />\n", $style); 

以上の単純

$this->print_html .= "<link href='$style' rel='stylesheet' type='text/css' />\n"; 
+0

行われて動作し、ありがとうは! – Curtis

関連する問題