I am trying to store a multiple line e-mail in an ini file using PHP/Zend Framework. My string has new lines characters in it, and when I use Zend_Config_Ini to parse the ini file, the new line characters come back escaped, so they are printed out on screen, instead of a line feed.
Example:
// ini file
message = Hi {0},\n\nThis is a test message.\nGoodbye!
is parsed by Zend_Config_Ini as:
Hi {0},\\n\\nThis is a test message.\\nGoodbye!
which then is printed out in the email as:
Hi John,\n\nThis is a test message.\nGoodbye!
Instead I want the e-mail to look like this:
Hi John,
This is a test message.
Goodbye!
Does anybody know how to achieve this? Thanks!
If you want to create a new INI file, you can create a .txt file first. Then, open this TXT file with Notepad, type command lines, click File > Save As, and then change the file name to XX.ini. In this way, you can create a new INI file. Of course, in the same way, you can convert an INI file into other file formats.
Escape newline character from a string in Python. Let’s understand this with an easy example: Assume that you have to print a path or directory location of your local drive. The path is: Now if you use the below code to print it out as a string: Output: The n appears in that string and n creates a new line.
// ini file message = Hi {0}, This is a test message. Goodbye! Hi {0},\ \ This is a test message.\ Goodbye! Hi John, This is a test message. Goodbye!
Use php constant: PHP_EOL
message = "Hi {0}," PHP_EOL PHP_EOL "This is a test message." PHP_EOL "Goodbye!"
Note that the constant PHP_EOL in application.ini must appear outside of the quotation marks. Otherwise it'll be interpreted as a literal.
What about using double-quotes arround your values, and using real newlines, like this :
message = "Hi {0},
This is a test message.
Goodbye!"
As an example, using this portion of code :
$config = new Zend_Config_Ini(APPLICATION_PATH . '/config/application.ini');
var_dump($config->production->testmessage);
die;
With application.ini
containing this :
[production]
testmessage = "this is
a new
message"
I get the following output from my var_dump
:
string(21) "this is
a new
message"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With