User Tools

Site Tools


If you want to send us your comments, please do so. Thanks
More on comments


Install PHP without Apache
PHP docs
O'Reilly PHP cookbook (First Edition, published November 2002)
Debugging PHP
Build in functions
Comparison Operators like !=
Composer, A Dependency Manager for PHP, on Wikipedia. Installation
W3schools tutorial
Wikibooks tutorial
Some more Tutorials and Scripts
XDebug is a PHP extension which provides debugging and profiling capabilities, Wikipedia
Read and write ods files

Run from the command line

--run, -r: Run PHP code without using script tags '<?..?>'
php -r 'echo "Hello\n";'

More examples

Run a PHP script

--file, -f: Parse and execute file
php -f script.php;

This does not work, presumed --version is a valid option:

php -f script.php --version;


Error in argument 3, char 2: no argument for option -

Run from a script

#! /usr/bin/php
// An (empty) line here results in an (empty) line in the output.
// An (empty) line here does not result in an (empty) line in the output.
echo "Hello\n";

Sample PHP web page

echo "Some teskt";
echo "<br>";
echo "Some more tekst";

Cannnot redeclare

PHP Fatal error: Cannot redeclare a_function() (previously declared in /home/domain/public_html/somefile.php:51) in /home/domains/public_html/somefile.php on line 60
A solution: the file somefile.php is placed in two folders of which one should not contain somefile.php

New line

This works in an offline php script

  echo "Hello\n\n\n\n`";

This does not work in an online php enabled webpage

  echo "Some teskt\nSome more tekst";
  echo "Some teskt\r\nSome more tekst";

We did not get the \n nor the \r\n newline to work in an online script. This works

  echo "Some teskt";
<br />
  echo "Some more tekst";

You can also use an inline php echo command to get a newline like in

  echo "Some teskt";
  echo "<br>";
  echo "Some more tekst";

This also works. Make sure the \n has a space before and after it like in the following example

  echo nl2br ("Some teskt \n Some more tekst");

In a Linux terminal running bash

php -r 'echo "Hello" . "\n";
php -r 'echo "Hello\n";'

Special operators

See Tokens on

  • :: T_PAAMAYIM_NEKUDOTAYIM Scope resolution operator . Also called Paamayim Nekudotayim (Hebrew for double colon)
  • -> T_OBJECT_OPERATOR (sometimes called: Member of object)



/usr/bin/php -r '$tel = 0; $tel++; echo "tel: $tel";'

Colored text

echo "\033[01;31mText in red\033[0m";


php -r 'for ($letters = "T"; $letters != "AE"; $letters++) { echo "$letters ";};'


<code php>printf “Percentage sign °”


Debugging PHP

  • When an error occurs it is possible that no output shows up, you get a blank screen. Not even the output of the echo commands which you inserted for debugging is shown
  • When you run the program and nothing happens start commenting out blocks of code from the end upwards until you get something that runs. Work from there downwards
  • Insert code that gives output of variables to get a better idea what is going on. Example: echo nl2br (“\n In file fof_db.php function fof_db_query 1\n”); . The 1 before the \n represents an index number
  • See for help. Warning: The Description of a command on can be confusing / misleading in our experience. What seems obvious is not always obvious
  • Install php-xdebug
  • Run php -l filename.php



Issue: “Call to undefined function json_decode()
Do: service php7.3-fpm restart

Issue: “Failed to restart php7.3-fpm.service: Unit php7.3-fpm.service not found.” Solution: T.b.d.


Timezone database is corrupt

PHP Fatal error:  date(): Timezone database is corrupt - this should *never* happen!

Solution: Check the timezone file in /usr/share/zoneinfo. The permissions should be 644. In our case the UTC file was, for some to us unknown reason, 640

Unexpected end of file

PHP Parse error:  syntax error, unexpected end of file, expecting '`' in /home/user/php/hello.php on line 11

Solution: remove the “`” (back tick) somewhere in the program

Call to undefined function

PHP Fatal error:  Uncaught Error: Call to undefined function


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

Privacy statement
Bugs statement
Copyright © : 2014 - 2022 and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
php.txt · Last modified: 21-12-2021 20:00 by wim