http://php.flashwebhost.com/sherly/age.php
Code:<?php $name = 'Joseph'; $yearBorn = 1975; $currentYear = 2014; $age = $currentYear - $yearBorn; print ("$name is $age years old. ")
http://php.flashwebhost.com/sherly/age.php
Code:<?php $name = 'Joseph'; $yearBorn = 1975; $currentYear = 2014; $age = $currentYear - $yearBorn; print ("$name is $age years old. ")
Semicolon at end of print statement missing.
print function same as echo, but use echo, forget print. echo is more popular, also there are more ways to print, some complicated, but is not required for most programming project.
Proper usageCode:print ("$name is $age years old. ")
OrCode:echo $name . ' is ' . $age . ' years old. ';
Advantage of using single quote is PHP know it is just string, so it will be faster. If using double quote, PHP compilter need to look for variable inside the string and convert it to its value, that need more processing time (not much, still do that way as a convention whenever possible).Code:echo "$name is $age years old. ";
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
http://php.flashwebhost.com/vineesh/...ariables_2.php
I was facing difficulty to insert a full stop after a sentence. But I managed to make it work. My code is
Is there any issue with this ?Code:<?php $staffName = 'Ramesh'; $companyName = 'HOSTONNET'; $staffName2 = 'Suresh'; $staffName3 = 'Tom'; echo $staffName . ' is working in ' . $companyName; echo '.'; echo ' But '; echo $staffName2; echo ' not.' ; echo '<br>'; echo $staffName3 . ' also working in ' . $companyName . 'for the past 10 years'; echo '.';
DAY 2 PHP PROGRAMMING
http://php.flashwebhost.com/tom/day_2_variables_1.php
Code:<?php $MovieName = '<b>Mr. Fraud</b>'; echo $MovieName ;
DAY 2 PROGRAMMING
http://php.flashwebhost.com/tom/day_2_variables_2.php
Code:<?php $MovieName = '<b>Mr. Fraud</b>'; echo 'Mohanlal\'s Upcoming Movie ' . $MovieName;
DAY 2 PROGRAMMING
http://php.flashwebhost.com/tom/day_2_variables_3.php
Code:<?php $MovieName = 'Mr. Fraud' ; $Starring = 'Mohanlal, Siddique, Dev Gill, Pallavi, Mia, Manjari' ; $Director = 'B. Unnikrishnan' ; echo $MovieName . ' is a malayalam movie, ' . $Director . ' is the Director. ' . $Starring . ' in the lead roles. ' ;
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
DAY 2 PHP PROGRAMMING
http://php.flashwebhost.com/tom/day_2_variables_4.php
Code:<?php $numOfBoys = '20' ; $numOfGirls = '25' ; echo 'Total number of students = ' . ($numOfBoys+$numOfGirls) ;
Last edited by image; 05-09-2014 at 10:48 AM.
This program have syntax error on line
$ missing for numgirls.Code:echo 'Total number of students = ' . ($numboys+numgirls) ;
Proper usage.
Only strings values need to be enclosed within quotes (' or ").Code:<?php $numBoys = 20; $numGirls = 25; echo 'Total number of students = ' . ($numBoys + $numGirls) ;
Variable names, if two words, Capitalize first letter of 2nd, 3rd, etc.. word.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
Try this
You can also replaceCode:<?php $staffName = 'Ramesh'; $companyName = 'HOSTONNET'; $staffName2 = 'Suresh'; $staffName3 = 'Tom'; echo $staffName . ' is working in ' . $companyName . '.' . ' But ' . $staffName2 . ' not.' ; echo '<br>'; echo $staffName3 . ' also working in ' . $companyName . ' for the past 10 years.';
WithCode:echo $staffName . ' is working in ' . $companyName . '.' . ' But ' . $staffName2 . ' not.' ; echo '<br>'; echo $staffName3 . ' also working in ' . $companyName . ' for the past 10 years.';
Code:echo '<p>' . $staffName . ' is working in ' . $companyName . '.' . ' But ' . $staffName2 . ' not.</p>' ; echo '<p>' . $staffName3 . ' also working in ' . $companyName . ' for the past 10 years.</p>';
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
Bookmarks