What Are Some Tips on a Bash Programmer Becoming a PHP Programmer?

Problem scenario
You are a Bash programmer, but you want to learn how to code in PHP.  How do you learn to develop PHP scripts when you have a Linux bash background?

If you are new to PHP programming and familiar with Bash programming, remember these tips:

1.  Variable assignments involve the variable with the syntax of a cash sign "$" before the variable name.  Here is an example:

$var4        = 4;

2.  An error such as this "PHP Parse error:  syntax error, unexpected '...' (T_VARIABLE) " can be caused by forgetting to have a semi-colon at the end of a line.  Here is an example:

$var1        = "A sentence";

3.  To concatenate strings, use a period between two variables like this:

$var3        = $var1.$var2;

4.  Here is a basic program to learn about arithmetic and conditionals:

   $var1        = "The beginning of a sentence";
   $var2        = " and other stuff.";
   $var3        = $var1.$var2;
   $var4        = 4;
   $var5        = 5;
   $var6        = $var4 - $var5;
   if ($var6 > 3) { echo "It is bigger than three!!!";}
   else { echo "It is not bigger than three!!!";}

Save the above file as test.php, and run it with this command: php test.php

Leave a comment

Your email address will not be published. Required fields are marked *