-1

I have the following function which I'm for enqueuing styles in PHP pretty similar to the WordPress function.

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;
}

And when calling this inside my index.php page, I do the following :

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

But it appears to just throw the whole print_html into 1 line which looks ugly within the source, any idea as to what I'm doing wrong here?

Curtis
  • 2,646
  • 6
  • 29
  • 53

1 Answers1

2

\n only works in a double quoted string i.e. echo "\n"; or in your case

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

Or done more simply

$this->print_html .= "<link href='$style' rel='stylesheet' type='text/css' />\n";
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149