LPM: Not quite Perl - PHP

David Hempy hempy at ket.org
Tue Aug 10 12:44:53 CDT 1999


Just saw this on CNet...

"PHP is a server-side, cross-platform, HTML embedded scripting language."  I
haven't used it yet, but it smells an awful lot like Perl.  It lets you embed
right into your HTML document code that will be interpreted by the web server
on its way to the client.  Hence, you can do stuff like this:

<html>
<body>
<h1> Countdown... </h1>
<?php
for ($i = 10; $i < 0; $i--) {
   print "$i...<br>\n"; 
} 
?> 

<blink>Blastoff!</blink>
</body>
</html>

It also claims to feature database connectivity and more.  If this sounds
appealing, walk through Cnet's article:
http://www.builder.com/Programming/PHPIntro/index.html and then visit the real
PHP home page.

As an interesting note, CNet's page on PHP syntax could have been a case study
for last night's discussion on hashes of hashes and arrays:
Arrays 
You set off array indices (regular or associative) with square brackets ([ and
]): 

$fruit[0] = 'banana'; 
$fruit[1] = 'papaya'; 
$favorites['animal'] = 'turtle'; 
$favorites['monster'] = 'cookie'; 

If you assign something to an array but leave the index blank, PHP assigns the 
object onto the end of the array. The statements about $fruit, above, produce
the 
same result as: 

$fruit[] = 'banana'; 
$fruit[] = 'papaya'; 

You can have multidimensional arrays, too: 

$people['David']['shirt'] = 'blue'; 
$people['David']['car'] = 'minivan'; 
$people['Adam']['shirt'] = 'white'; 
$people['Adam']['car'] = 'sedan'; 

A shortcut for creating arrays is the array() function: 

$fruit = array('banana','papaya'); 
$favorites = array('animal' => 'turtle', 
                    'monster' => 'cookie); 

or 

$people = array ('David' => array('shirt' => 'blue', 
                                    'car' => 'minivan'), 
                 'Adam' => array('shirt' => 'white', 
                                    'car' => 'sedan')); 

(note that this is PHP, not perl.  I'm not perlish enough to know if the syntax
is identical, but it sure looks a lot like what was on the flipchart last
night.)

-dave


--
David Hempy
Internet Database Administrator
Kentucky Educational Television
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/lexington-pm/attachments/19990810/42076ee0/attachment.htm


More information about the Lexington-pm mailing list