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.

Aug 122010
 

Cross platform newline in PHP

Answer:

In PHP, if you want to print out a newline character, you can use the "\n" character

<?php

    echo "Hello World\n";

But the \n" character only work in Linux/UNIX, to make it work for both Windows, Mac and Linux/UNIX platforms, you can use a special constant PHP_EOL.

<?php

    echo "Hello World" . PHP_EOL;
Aug 092010
 

Update the Channel List using PHP/PEAR

Answer:

PEAR is a framework and distribution system for reusable PHP components. To update the channel list, what you need to do is type the following command.

# sudo pear channel-update pear.php.net

Aug 082010
 

Syntax highlighting in PHP

Anwser:

PHP has a built-in function that help to to syntax highlight your PHP codes.

E.g.

<?php

$str = <<<EOT

    echo "This is a test";


EOT;

highlight_string($str);
Aug 072010
 

Solving the warning message "Xdebug MUST be loaded as a Zend extension"

Answer:

If you have installed the xdebug, and the PHP interpreter show the following warning message every time you execute the php command.

Xdebug MUST be loaded as a Zend extension

It can be solved by adding the following line in your php.ini (Replace the path of you xdebug.so if they are different.)

zend_extension="/usr/local/php/modules/xdebug.so"

And remember to remove any statement like the following which caused the problem..

extension="xdebug.so"

Aug 032010
 

Output the parsable string representation of a variable in PHP

Answer:

var_export allows you to outputs or returns a parsable string representation of a variable.

Example:

<?php

$a = array (
        "foo" => 1,
        "bar" => 2
    );

echo var_export($a);

It gives:


array (
  'foo' => 1,
  'bar' => 2,
)

So you can use the output to declare the variable again in another PHP file.