HAL-PC Scheduled Classes TWiki > Classes > IntroPHP2 ( vs. r1.1) TWiki webs:
AIX| Classes | HALBOD | HLUG | Helpdesk | Library | Main | Samba | TWiki |
Classes . { TWikiGuest | Index | Changes | Search | Go }
 <<O>>  Difference Topic IntroPHP2 (r1.1 - 17 Sep 2004 - RickArchibald)
Added:
>
>
%META:TOPICINFO{author="RickArchibald" date="1095393780" format="1.0" version="1.1"}% %META:TOPICPARENT{name="IntroPHP1"}% Houston Area League of PC Users Education System <BODY BGCOLOR="#e2e3ed" TEXT="#07070a" LINK="#777bb4" ALINK="#777bb4" VLINK="#777bb4">
php logoPHP stands for PHP: Hypertext Preprocessor.
http://www.php.net
Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

A variable holds a single piece of information, similar to a number or a character string. Variables can be used for a number of things.
Let's create a simple HTML form and ask for some information, like a persons name.
Please open notepad on your computer:

* From the Start menu, select Programs
* From the Accessories menu, select Notepad


The Notepad window is displayed.
Enter the following text into your text file:

<html>
<body>

<form>
Name:
<input type="text" name="name">
</form>

</body>
</html>
We will save the file with .html as the extention.
Please save your file in c:/windows/temp as name.html
To prevent the .txt extension being appended to your saved file name, enclose the filename in quotation marks: "name.html", when typing it into the Save As dialog box.
Let's place this html form on the web server so we can see what it does without PHP.
Windows 2000: click Start, then Run, and then type: cmd.exe and click OK.

> c:

> cd windows/temp

> ftp www.hal-pc.org

220 delphi.hal-pc.org FTP server (Version 6.00LS) ready.
Name (www.hal-pc.org:anne): phpx
331 Password required for phpx.
Password: phpx
230 User phpx logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
150 Opening ASCII mode data connection for '/bin/ls'.
total 30
drwxr-xr-x 8 phpx operator 3072 Sep 11 16:16 public_html
-rw-r--r-- 1 phpx operator 229 Sep 11 16:26 quota
226 Transfer complete.
ftp> cd public_html
250 CWD command successful.
ftp> put name.html
local: name.html remote: name.html
150 Opening BINARY mode data connection for 'name.html'.
100% |**************************************************| 1444 00:00 ETA
i 226 Transfer complete.
1444 bytes sent in 0.05 seconds (30.82 KB/s)
ftp> chmod 755 .
ftp> bye
221 Goodbye.
Open a browser on your computer.
In the location bar enter the URL:
http://www.hal-pc.org/~phpx/name.html
rename name.html to name.php
Follow the previous instructions to place name.php on www.hal-pc.org using ftp.
Open a browser on your computer.
In the location bar enter the URL:
http://www.hal-pc.org/~phpx/name.php
As you see, the name of the file does not make any difference as long as the file contains only html.
Now lets get the name that is entered into the form and display it using PHP
This is where we begin to see the power of variables.
open name.php in notepad

Let's insert the following lines and modify our original name.php:

<?php

$name2=$HTTP_POST_VARS["name2"];

echo "<br>".$name2."<br>";

?>

To create a file that looks like this:

<?php
$name2=$HTTP_POST_VARS["name2"];
?>

<html>
<body>

<?php
echo "<br>".$name2."<br><br>"; ?>

<form name=see_name action=name.php method=post>
Name:
<input type="text" name="name2">
</form>

</body>
</html>

What have we done?
1. We have used the predefined PHP variables $HTTP_POST_VARS to acquire the data that the client entered into their browser.

For a complete list of PHP's Predefined Variables go to: http://us4.php.net/manual/en/reserved.variables.php

2. We have used the PHP language construct: echo to display the data.

3. We have used one of the string operators. The concatenation operator ('.') is the glue in our echo statement.

$newsplit="";
if($name<>"")
{
$name=trim($name);
$name=strtolower($name);
$newsplit = explode(" ", $name);
$name="";
$to_do=count($newsplit)+1;
for($y=0; $y < $to_do; $y++)
{
$newsplit[$y]=ucfirst($newsplit[$y]);
$name=$name." ".$newsplit[$y];
}
$name=trim($name);
$name = ereg_replace('[^._ 0-9a-zA-Z]', '', $name);
}

Next    Next!


-- Main.RickArchibald - 17 Sep 2004

Topic IntroPHP2 . { View | Diffs | r1.1 | More }
Revision -
Revision r1.1 - 17 Sep 2004 - 04:03 GMT - RickArchibald
Copyright © 2003-2007 by F. A. Archibald III & the contributing authors