Saturday, 26 July 2014

String functions in php

Php string functions:

                           There are many strings functions in php but discuss some common with example that is use frequently in php.


Echo/Print function

Print /echo function:

                                    In php we use print or echo function for display the output of one or more stirngs. Print function always return value 1 whenever echo does not return any value .so that’s why echo is faster than print . so echo is more use function in php for displaying out put .we can use print function with () or without ()

Example:

<?php
echo “hello php”;
echo “<br/>”;
print “hello php”;
$val=10;
echo “the value is= $val” ;
print “<br/>”;
print  ”the value is =$val”;
?>

Output:

           hello php
           hello php
           the value is=10
           the value is=10

Video

                                                         see video tutorial 2





Variable in php

Variables in PHP

Variables are used  for store different type of values, like text , numbers.
When a variable is declared, it can be used again anywhere in your script.
All variables in PHP start with a $ sign symbol.
Example for declaring php variable
$variable_name=value;
Php is loosly typed language a php variable can store all type of value it does not need to specify one type of variable.

 Rules for declaring variables:

             Rules for naming php variable is jst like c++ variable.
·         A variable must be start with letter or underscore(_).
·         It not includes the space.

String Variables in PHP:

  For strings In php we simply declare a variable as show above and assign it string value in double quotes.

For example:

 <?php

$text=”hello umer”;

echo $text;

?>

We use the echo for print the value in php.

Concatenate strings:

                     For concatenate different strings with each other we use dot (.) operator in php .

For examples:

 <?php

$text=”hello umer”;

$text_2=”h r u?”;

$text_3=$text. $text_2;

 echo $text_3;

?>

Output:

          Hello umer h r u?





Syntax of php

PHP Syntax:

A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.

Comments in PHP:


In PHP, we use // to make a single-line comment or /* and */ to make a large comment block like c and c++.


Introduction Of php

starting php:

Before you start you should have a basic understand of the following languages:
  • HTML
  • JavaScript
  • css

Php introduction:

  • PHP is stand for: Hypertext Preprocessor language
  • It  is a server-side  language that execute on the  server
  • it supports many type of databases  like mysql
  • PHP is an open source software
  • PHP is free to download and use

Where to Start?


  • Install Wamp server on your system which run the php code on your system and made your system like server
  • It support the mysql 


Saturday, 1 February 2014

write a program in c++ that calculate leap year

Example 4 if,else statement:

logic:
         here the main logic is that "the year which will divide by 4 and reminder is zero then the year will be leap otherwise not" so we take the modules of year by and check the year is leap or not.

program:

#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
void main()
{
int year;
cout<<"enter the year==";
cin>>year;
if(year%4==0)
cout<<"leap year";
else
cout<<"not a leap year";
_getch();

}

                                                                DOWNLOAD .CPP FILE




write a program in c++ that take your marks as input and display your grade as output.

Example 3 nested if,else statement:

statement:

write a program in c++ that take your marks as input and display your grade as output.

logic:

      we simply use nested if,else statement because we have multiple choices. first of all we have to understand the grading system every institute have own grading system i made this program according to my institute. here  first if condition will be  true if the marks between 100 and 84.5 then output will be A+. if the first condition is false then compiler will check the second condition if this condition is true then then compiler will run its block of code and leave all condition similarly it will be done for all conditions. else block will be run if all if condition will be false.

program:

#include "stdafx.h"
#include "iostream"
#include"conio.h"
using namespace std;
 void main()
{
int marks;
            cout<<"enter the marks==";
cin>>marks;

       if(marks>=84.5 && marks<100 )
        {cout<<"your grade is A+";}
else
if (marks>=79.5 && marks<84.5)
{
cout<<"your grade is A";
}
else
if (marks>=74.5 && marks<79.5)
{
cout<<"your grade is B+";
}
else
if (marks>=69.5 && marks<74.5)
{
cout<<"your grade is B";
}
else
if (marks>=64.5 && marks<69.5)
{
cout<<"your grade is B-";
}
else
if (marks>=59.5 && marks<64.5)
{
cout<<"your grade is c+";
}
else
if (marks>=54.5 && marks<59.5)
{
cout<<"your grade is c";
}
else
if (marks>=49.5 && marks<54.5)
{
cout<<"your grade is D";
}
else
if (marks<49.5 && marks>=0)
{
cout<<"your grade is F";
}
else
{
cout<<"wrong entry";
}
_getch();       

}
                                                     
                                                             DOWNLOAD .CPP FILE