Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 252010
 

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;
Jul 242010
 

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;
Jul 112010
 

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,
);