Multi-line string in PHP
Answer:
To assign a multi-line string to a variable, is easy with the Heredoc
E.g.
<?php
$text = <<<EOT
<p>
this "is" a 'test'
</p>
EOT;
echo $text;
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Multi-line string in PHP
Answer:
To assign a multi-line string to a variable, is easy with the Heredoc
E.g.
<?php
$text = <<<EOT
<p>
this "is" a 'test'
</p>
EOT;
echo $text;
Multiline string in Perl
Answer:
You can either use the q operators.
my $s = q#''''"
test
"""'
#;
print $s;
Or qq operators if you need interpolation.
my $d = "test";
my $s = qq#''''"
$d
"""'
#;
print $s;
Sort an array by key in PHP
Answer:
Assume you have an array in PHP as following,
$a = array (
"orange" => 3,
"mango" => 2,
"apple" => 1,
);
You can sort the array by the key, with the ksort function
ksort($a);
Then the array become:
(
"apple" => 1,
"mango" => 2,
"orange" => 3,
);
How to sort a list in Python?
Answer:
Use the sorted method.
list = [3, 2, 1]
print sorted(list)
It will give:
[1, 2, 3]
Check which character encodings are supported by Perl
Answer:
Use the following command to check which character encodings are supported by Perl.
# perl -MEncode -le "print for Encode->encodings(':all')"