From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Storing numbers and text in variables

Storing numbers and text in variables - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Storing numbers and text in variables

PHP variables can store many different types of information. For the time being, let's just focus on how you store numbers and text in a variable. We'll also look at the important role the semicolon plays in PHP. This page, variables.php, contains a simple template for a webpage about a book. I'm going to add my PHP code above the doc type, so if I put my insertion point up there, add in a couple of extra lines, then an opening PHP tag. Open angled bracket, question mark, PHP. And down here a closing tag which is a question mark and a closing angle bracket. It might seem strange to you that I'm putting the PHP code above the doc type. But remember, PHP code is processed by the server, and that's where it stays. So as long as the PHP code doesn't output any HTML, it's okay. Above the doc type, that will remain at the top of the page when it's received by the browser. So let's add our first variable. This one will be a number. We'll call it answer. Variables always begin with a dollar…

Contents