Archive:PHP and MySQL Programming/Syntax Overview: Difference between revisions

wikademia>Kencyber
wikademia>Wikademia
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== PHP tags: ==
== PHP tags: ==
 
{{ntnes}}
=== '''<?php [code] ?>''' ===
=== '''<?php [code] ?>''' ===


* Enclose php code
* Enclose php code


* Can be configured in the php.ini to be <? ?>, <script language="php"> </script> etc.
* Can be configured in the <code>php.ini</code> to be <code><? ?></code>, <code><script language="php"> </script></code> etc.


* Embedded in normal HTML code
* Embedded in normal HTML code
Line 15: Line 15:
<source lang="php">
<source lang="php">
  <?php
  <?php
  print “Hello World\n”;
  print "Hello World\n";
  $date = date(“Y-m-d H:i:s”);
  $date = date("Y-m-d H:i:s");
  print “The date and time at the moment is $date”;
  print "The date and time at the moment is $date";
  ?>
  ?>
</source>
</source>
Line 41: Line 41:


<source lang="php">
<source lang="php">
  <?=date(“Y-m-d H:i:s”)?>  
  <?=date("Y-m-d H:i:s")?>  
</source>
</source>


Which will output something like ''2005-11-09 19:40:05''.
Which will output something like ''2005-11-09 19:40:05''.
[[]]


== Commenting ==
== Commenting ==
Line 54: Line 55:
* Example:
* Example:
<source lang="php">
<source lang="php">
  echo “Hello”; # Everything from the hash is commented out
  echo "Hello"; # Everything from the hash is commented out
</source>
</source>


Line 186: Line 187:
* Example:
* Example:
<source lang="php">
<source lang="php">
$a = “Fill the halls “;
$a = "Fill the halls ";


$b = “with poisoned ivy...“;
$b = "with poisoned ivy...";


$c = $a . $b;  # the '.' operator concatenates two variables.
$c = $a . $b;  # the '.' operator concatenates two variables.


// $c = “Fill the halls with poisoned ivy...”
// $c = "Fill the halls with poisoned ivy...";
</source>
</source>


Line 211: Line 212:
// $a[3] = 4;
// $a[3] = 4;


$b = array(“name” => ”Fred”, “age” => 30);
$b = array("name" => "Fred", "age" => 30);


// $b['name'] = “Fred”;
// $b['name'] = "Fred";


// $b['age'] = 30;
// $b['age'] = 30;
Line 349: Line 350:
      
      
     function who_am_i() {
     function who_am_i() {
       echo "My name is {$this->name), and I am a dog";
       echo "My name is {$this->name}, and I am a dog";
     }
     }
  }
  }