Skip to main content

Posts

Showing posts with the label IntroPHP

PHP String Variables tutorial

A string variable is used to store and manipulate text. String Variables in PHP String variables are used for values that contain characters. In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP. After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable. Below, the PHP script assigns the text "Hello World" to a string variable called $txt: <?php $txt="Hello World"; echo $txt; ?> The output of the code above will be: Hello World Now, lets try to use some different functions and operators to manipulate the string. The Concatenation Operator There is only one string operator in PHP. The concatenation operator (.)  is used to put two string values together. To concatenate two string variables together, use the concatenation operator: <?php $txt1="Hello World!"; $txt2="What a nice day...

Variables in PHP - Create, Assign, Display

A variable is used in PHP scripts to represent a value. As the name variable suggests, the value of a variable can change (or vary) throughout the program. Variables are one of the features that distinguish a programming language like PHP from markup languages such as HTML. Variables allow you write your code in a generic manner. To highlight this, consider a web form which asks users to input their name and favorite color. Every time the form is completed, the data will be different. One user may say his name is John and his favorite color is blue. Another may say her name is Susan and her favorite color is yellow. We need a way of working with the values a user enters. The way to do this is by using variables. There are a few standard variables that PHP creates automatically, but most of the time variables are created (or declared ) by you, the programmer. By creating two variables called $name and $color , you could create generic code which can handle any input va...