PHP - String中的换行符不起作用

I have an array with strings. The strings shall have line breaks. My code produces the
as text not as tag. How can I manage to create a
tag in the HTML that creates a line break?

<?php return array(
  ....
  'subtitle'    => nl2br("My Sentence shall have a 
 line break right there") ,
 ...
);


 <title><?php echo htmlspecialchars($CONFIG['subtitle']); ?></title>

Result

   My Sentence shall have a <br> line break right there

As most answers have suggested, remove the htmlspecialchars section. Also, your should be replaced with for environments that don't recognize only the . The updated code should look like below:

<?php return array(
  ....
  'subtitle'    => nl2br("My Sentence shall have a 
 line break right there") ,
 ...
);


 <title><?php echo $CONFIG['subtitle']; ?></title>

Hope that helps.

The htmlspecialchars does not do

" " => "<br/>"

http://php.net/htmlspecialchars

The translations performed are:

'&' (ampersand) becomes '&amp;'
'"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set.
"'" (single quote) becomes '&#039;' (or &apos;) only when ENT_QUOTES is set.
'<' (less than) becomes '&lt;'
'>' (greater than) becomes '&gt;'

Edit: As the comment below says, http://php.net/nl2br is the best solution.

You need to use a str replace or regex replace or something: http://php.net/manual/en/function.str-replace.php

If you skip the htmlspecialchars you get the desired behaviour

 echo $CONFIG['subtitle'];

It replaces your tags so they can be printed in html, and you dont want that

Change your code with:

<?php return array(
  ....
  'subtitle'    => "My Sentence shall have a 
 line break right there",
 ...
);


 <title><?php echo nl2br(htmlspecialchars($CONFIG['subtitle'])); ?></title>