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

Turn on all error reporting in PHP

Answer:

Sometimes, when debugging, it is helpful when you need to enable all PHP errors and make them visible in your application (not in the log), you can put the following line at the top of your script.

<?php

    error_reporting(E_ALL);