Results 1 to 10 of 50

Thread: Day 2 - Variables - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    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

    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 '.';
    Is there any issue with this ?

  2. #2
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 2 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_2_variables_1.php

    Code:
    <?php
    
    
    $MovieName = '<b>Mr. Fraud</b>';
    
    
    echo $MovieName ;

  3. #3
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    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;

  4. #4
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    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. ' ;

  5. #5
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by image View Post
    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;
    Variable names always start with smaller case letter.

    Code:
    <?php
    
    
    $movieName = '<b>Mr. Fraud</b>';
    
    
    echo 'Mohanlal\'s Upcoming Movie '  .  $movieName;
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  6. #6
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    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.

  7. #7
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by image View Post
    DAY 2 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_2_variables_4.php

    Code:
    
    <?php
    
    
    $numboys = '20' ;
    $numgirls = '25' ;
    
    
    echo 'Total number of students = ' . ($numboys+numgirls) ;

    This program have syntax error on line

    Code:
    echo 'Total number of students = ' . ($numboys+numgirls) ;
    $ missing for numgirls.

    Proper usage.

    Code:
    <?php
    
    $numBoys = 20;
    $numGirls = 25;
    
    echo 'Total number of students = ' . ($numBoys + $numGirls) ;
    Only strings values need to be enclosed within quotes (' or ").

    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.

  8. #8
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by vineesh View Post
    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

    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 '.';
    Is there any issue with this ?

    Try this

    Code:
    <?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.';
    You can also replace

    Code:
    echo $staffName . ' is working in ' . $companyName .  '.' .  ' But ' . $staffName2 . ' not.' ;
    
    echo '<br>';
    
    echo $staffName3 . ' also working in ' . $companyName . ' for the past 10 years.';
    With

    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.

  9. #9
    Join Date
    May 2014
    Posts
    21

    Arrow suggestions

    Quote Originally Posted by vineesh View Post
    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

    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 '.';
    Is there any issue with this ?
    your code is working and error free. I also got a suggestion that it could be reduced too.
    i have modified your code in here:
    Code:
    <?php
    
    
    $staffName = 'Ramesh';
    $companyName = 'HOSTONNET';
    
    
    $staffName2 = 'Suresh';
    
    
    $staffName3 = 'Tom';
    
    
    echo $staffName . ' is working in ' . $companyName.'. But '.$staffName2.' is not.<br>'.$staffName3.' also working in '.$companyName .' for the past 10 years.';
    you could do everything in one echo. lesser code faster work ;)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •