Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA249      CA318      CA425      CA651

w2mind.computing.dcu.ie      w2mind.org


PHP

Server-side scripts.

file.php

Contains normal HTML, and then PHP code mixed in, delimited as follows:

<html>
<body>

html code

<?php 
php code 
?>

more html code

PHP gets interpreted on server side before resulting HTML stream is returned to client.
Client can't see PHP code: Unlike the case with Javascript, client can't see the code that generated the HTML.
PHP used for interaction with data on server (e.g. database).



Reference



Environment and calling programs



Example



Call with arguments

PHP can be used with arguments in the URL.
This is like a CGI script with HTTP GET, like a Google search.

http://host/prog.php?variable=value
Example:
world.php?world=w2m.TyrrellWorld
Parsed like this in world.php:


<html>

<?PHP
	
$qs=$_SERVER["QUERY_STRING"];

parse_str ( $qs );

// $world is now defined as whatever the value was

?>

<head>

<?PHP
	 
 print "<title> World: $world </title> \n"; 

....
 



Stand-alone PHP scripts

Can use PHP as just general offline scripting language.
Can run Stand-alone PHP scripts at command-line. Something like:

#!/usr/local/bin/php 

Whatever is outside PHP is just displayed.

<?php

// echo PHP_VERSION;

 print "Name of script = $argv[0] \n"; 
 print "First command-line arg = $argv[1] \n"; 

 print "All command-line args: \n";
 print_r($argv); 
 print "\n"; 

?>

Whatever is outside PHP is just displayed.

On DCU Linux, this works for ssh login:
#!/local1/php5/bin/php 



Search www.php.net: with Google.





Feeds      HumphrysFamilyTree.com

Bookmark and Share           On Internet since 1987.