PHP String Functions

PHP String Functions:

As we Learn in the earlier lesson string is the sequence of alphabets/characters. Here we touch some PHP strings functions which are most usage in PHP language.

PHP Strlen() Function:

“Knowledge idea” is like a String. So we use length string function which task to count the alphabets of strings and display output on screen.Let’s take following example.

php
$x="Knowledge idea";
echo strlen($x); // Answer is 14
?>

In above case first we assign a string to a variable $x then print the string value in strlen() function. Keep remember in mind space will consider/count then answer will be display with string characters include spaces.

PHP Strpos() Function:

PHP Strpos() is used to find a special/specific alphabet/character in the given string. If function got it then function return the first match position of the string. In the other condition not found function will return False.Let’s take the following example.

php
$x="knowledge idea";
echo strpos($x,"idea"); // Answer is 10
?>

 According to your perceptions answer is 11. But you compiler shows 10. The reason is that string count start from 0 not 1.

List of PHP String function more…

PHP Data Types

PHP Data Types:

PHP variables stores data in the different data form some are in numeric or some in alphabets. According to Wikipedia data type is a set of values. PHP data types has several data types.We will discuss all types step by step. 

  1. String 
  2. Integers 
  3. Floating point numbers
  4. Boolean
  5. Array
  6. Object
  7. NULL

1. PHP Strings

As we read previous lesson about strings exactly same thing happen here. We can say string could be a text like “Hello World” In other words strings is a sequence of alphabets/characters. Remember put quotes around the text/character.We simply assign a text value to variable to explain strings. Let’s take example.

php
$x="Knowledge idea";
echo $x;
$x='Knowledge idea';
echo $x;
?>

we could be use double quotes or single quotes around the characters in strings  result will be same.

2. PHP Integers

Integers are whole numbers, without decimal point. Integers similar to the whole numbers.Integers could be positive or negative.Integers can be written in three formats.

  • Decimal
  • Hexadecimal 
  • Octal

Let’s take the following example to express the Integers.

php
// var_dump() return the data type and variable value
$x= 1234; //Positive Numeric Value 
var_dump($x);
echo 
$y= -1234; // Negative Numeric Value 
var_dump($y);
echo 
$z= 0x1234; // hexadecimal number
var_dump($z);
echo 
$v= 01234; // octal number
var_dump($v);
echo 
?>

3. Floating Point Numbers

Floating point number is the number in which decimal point exist. In C floating point numbers are corresponding to the double data type. PHP admit two types of floating point numbers. Literal number with decimal point and other is with scientific notation. Like as 9.85D-6. Let’s take the next floating point number example.

php
// var_dump() return the data type and variable value
$x= 1.234; // with Literal Numeric value 
var_dump($x);
echo 
;
$y= 1.2D4; // with Scientific Notation
var_dump($y);
echo 
;
$z= 2E-4; // with Scientific Notation 
var_dump($z);
echo 
;
?>

4. PHP Boolean

Boolean have two values either  True or False. Take following example.

php
$p= True;
$q= False;

// Take test example which is most usage in programming if/else
   structure

if (True)
   print{"You are beautiful"};
else 
   print{"You are not beautiful"}

// with False

if (False)
   print{"You are beautiful"};
else 
   print{"You are not beautiful"}
?>

5. PHP Array

Array have multiple/group of values in single variable.Array values are related data components.

php
$Country=array('America','England','Japan');
echo $Country;

// Take test with array position

$data[0]= "John is Funny";
$data[1]= "John is Rude";
$data[2]= "John is Rock";
$data[3]= "John is cute";
?>

As you seen above we describe array appoint a value to array position by specifying which array element you want to appoint a value.

6. PHP Objects

PHP Object is a data type which may store info and data.Object  Information and data need absolutely declared. In the beginning of object we declare class and assign a keyword related to his class. And class is a frame that consist of properties and methods. 

7. PHP NULL

The special NULL value show that a variable has no value. NULL is the only possible value PHP data type NULL. The NULL value diagnose in case a variable is blank/empty. 

php
$a="Knowledge idea";
$a= NULL;
// var_dump() return the data type and variable value
var_dump($a);
?>

Grab/copy to clipboard all over these PHP data types codes above and practice as yourself — If make any error you may discuss on comments & feedback.

PHP echo statement & Print statement

PHP echo statement & Print Statements:

Now we learn about PHP output statements.These two statements are essential to get output.
1. PHP echo statement
2. PHP print statement

But here is little bit difference between them.

1. Echo return output more strings.
2. Print return output only one string & print always return 1.

php 
echo "

Welcome to Knowledge idea !!

";
echo "Practice makes a men perfect
";
?>

Above examples shows php echo output with strings.Please keep in mind always use quotes around the text/character.
Secondly we discuss on string and variable usage with PHP echo output statement.
Let’s take example.

php 
$info="Just do it";
$data="Necessary is the";
$text="mother of invention"; 
$Home=array("Florida","London","New York","Japan"); 
echo $info
echo $data $text
echo "My Home at {$Home[1]}";
echo "{$Home[0]} is a beautiful place"; 
?>

As you seen,Above example consist on variable such as $data,$info,$text and other’s. which are working with output statement echo.Keep in mind “$” sign declare the variable.

Print Statements:

Comeback on previous topic print is also used to get output.
Let’s take an example with few strings.

php 
print "

Welcome to Knowledge idea !!

";
print "I Want to earn knowledge about php
";
?>

This following example showing the variable and strings with print statement.

php 
$info="Just do it";
$data="Necessary is the";
$text="mother of invention"; 
$Home=array("Florida","London","New York","Japan"); 
print $info
print $data $text
print "My Home at {$Home[1]}";
print "{$Home[0]} is a beautiful place";  
?>

Both are approximately same output statements.
Practice as yourself !!

PHP Variable scope

PHP Variable &  Declare Variable:

In this php course we learn about php variable using algebraic terms. In algebra we use “p” “q” like these alphabets to hold different numeric values like “2” “3” . Lets Suppose we assume a formula  r=p+q so we will get 5 out of this formula. Lets take this formula in php variable example.

php 
$p=2; 
$q=3; 
$r=$p+$q; 
echo $r; 
?>

Above php code “$” declare the variable. php case-sensitive that’s why $P & $p is two different php variable.Keep remember in mind uppercase and lowercase alphabets not declare same variable. php variable name cannot begin with numbers.

Declare Variable:

php 
$name="Knowledge idea";
$data="Jhon have two tablets";
echo $name;
echo $data;
?>

Note: when you appoint a text to variable so put quotes around the text. check the below highlighted example.

php 
$text="Put quotes around the text";
?>

PHP is a closely language because above all examples we didn’t declare that which data type and name of the variables before to utilize it.On the other hand-side in Java,C++ a developer must declare data type.

Local & Global area variable declaration:

A variable declare outside of a function has a global area and can accessed only outside of this function. A variable declare Inside of a function has a Local area and can accessed only Inside of this function. Lets take an example both areas.

php 
$p=2; //Global Area & it access only outside of area
function take demo() {
$q=3; //Local Area & it access only inside of area
echo "demo variable inside the function";
echo "Variable of $q";
echo 
;
echo "Variable of $p";
}
take demo()
echo "demo variable outside the function";
echo "Variable of $p";
echo 
;
echo "Variable of $q";
?>

Above line”6″ highlighted shows Local Area/scope.Second below line”12″ shows global Area/scope. Grab these above codes and try it yourself !!

PHP Courses – web development For Beginners

PHP training for beginners:

PHP Courses teaches you how to create most reliability in your development task/projects. PHP is a server scripting language PHP Also used as general purpose programming language that is useful and sturdy gadget to build dynamic websites.PHP can easily mixed up with HTML Language. PHP installed on more than 240 million websites.

Firstly we need to know what that its means PHP ?

PHP Stands for (Hypertext Preprocessor) Language used widely Mostly its usage in web development and other various development but here we only discuss PHP Beginning tutorials. How we start PHP code.

php 
echo"Welcome to knowledge idea"; 
?>

Grab above lines and practice as yourself !!