Re: define ('NL', "<br />"); can I define a constant var ? [message #180191 is a reply to message #180180] |
Wed, 23 January 2013 09:55 |
Arno Welzel
Messages: 317 Registered: October 2011
Karma:
|
Senior Member |
|
|
Am 22.01.2013 19:43, schrieb Luuk:
> On 22-01-2013 09:39, Arno Welzel wrote:
>> cate, 2013-01-22 01:06:
>>
>>> I can see why this doesn't work:
>>>
>>> define ('NL', '<br />');
>>> echo "This is NL another line";
>>>
>>> Is there a way to define a constant variable in PHP?
>>
>> Maybe you want to look at the documentation:
>>
>> <http://php.net/manual/en/language.constants.php>
>>
>> So - yes the define is OK.
>>
>> But your echo will not work, since NL is not automatically treated as a
>> placeholder. You have to write:
>>
>> echo "This is ".NL." another line";
>>
>> With variables this would be easier though:
>>
>> $NL = '<br />';
>> echo "This is $NL another line";
>>
>
> Why do you use single quotes on the first line,
> and double on the second?
To avoid substitutions and to make clear, that the string is a literal.
> Why not simply use double-quotes everywhere.....
Because then $foobar would be treated as a variable or /n would be
treated as newline and not as literal '/n'.
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
|
|
|