Chapter 3. PHP Syntax: Weird and Wonderful
Youâve got a couple of PHP programs running, and have a handle on how PHP can interact with an HTML form. Still, although youâre a little more comfortable with how PHP as a whole interacts with web servers and web browsers, whatâs actually going on in those PHP scripts? Itâs time to dig a good deal deeper and start to understand whatâs going on in the code youâre writing. In this chapter, youâre going to get comfortable with a lot of the PHP syntax. That means learning what special wordsâusually called keywordsâyou type into your programs and what each one of those keywords instructs PHP to do.
Fortunately, this learning doesnât mean you canât still build interesting programs that run in a web browser. In fact, because almost everything thatâs done with PHP involves web pages, all of your scripts in this chapter will accept information from a web form and work with that information. So, youâre not just learning PHP; youâre learning to write web applications.
Get Information from a Web Form
In sayHelloWeb.php, you used the following line to get the value of a variable called ânameâ from the sayHello.html web form:
echo $_REQUEST['name'];
You might remember that $_REQUEST
is a special PHP variable that lets you get information from a web request (Check Things Out Locally). You used it to get one particular piece of informationâthe userâs nameâbut it can do a lot more.
Note
You can find the finished example ...
Get PHP & MySQL: The Missing Manual, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.