Free web hosting services - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY You

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY You can use echo with variables, numbers, and strings. Simply put it in front of whatever you want to display, like this: $name = ‘David’; echo $name; // displays David echo 5; // displays 5 echo ‘David’; // displays David The important thing to remember about echo and print, when using them with a variable, is that they work only with variables that contain a single value. You cannot use them to display the contents of an array or of a database result. This is where loops are so useful: you use echo or print inside the loop to display each element individually. You will see plenty of examples of this in action throughout the rest of the book. You may see scripts that use parentheses with echo and print, like this: echo(’David’); // displays David The parentheses make absolutely no difference. Unless you enjoy typing purely for the sake of it, I suggest you leave them out. Joining strings together PHP has a rather unusual way of joining strings (text). Although many other computer languages use the plus sign (+), PHP uses a period, dot, or full stop (.) like this: $firstName = ‘David’; $lastName = ‘Powers’; echo $firstName.$lastName; // displays DavidPowers As the comment in the final line of code indicates, when two strings are joined like this, PHP leaves no gap between them. Don t be fooled into thinking that adding a space after the period will do the trick. It won t. You can put as much space on either side of the period as you like; the result will always be the same, because PHP ignores whitespace in code. You must either include a space in one of the strings or insert the space as a string in its own right, like this: echo $firstName.’ ‘.$lastName; // displays David Powers The period or concatenation operator, to give it its correct name can be difficult to spot among a lot of other code. Make sure the font size in your script editor is large enough to read without straining to see the difference between periods and commas. Working with numbers PHP can do a lot with numbers from simple addition to complex math. The second half of this chapter contains details of the arithmetic operators you can use with PHP. All you need to remember at the moment is that numbers mustn t contain any punctuation other
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Leave a Reply