Sunday, 7 August 2016

PHP Introduction Lecture #10

PHP BUILT-IN FUNCTIONS

Hello All... welcome every one. I'm going to start PHP lectures for Very Beginners, who wants to learn PHP from very beginning. No matter if you do not have any basic programming concept. If you follow my tutorials I hope you will surely get some how good knowledge of PHP.
Today our Topic is

BUILT-IN FUNCTIONS

In PHP there are more than 700 built-in functions, the PHP is powerful and one of the most emerging technology just because of its powerful functions. We will discuss here some of the major built-in functions.
i-                   strlen();
ii-                 chr()
iii-               ord()
iv-               substr()
v-                 round()
vi-               ceil()
vii-             floor()
and many more from the php.net official website of PHP. Let’s discuss each of them.
i-                   strlen(): this function returns the total length of a string or sentence. And inside parentheses you can give any string or a variable that store a string value.
<?php
            $string = “this is string”;
            echo strlen($string);
?>
The result will be 14. Because it also counts space as a single character. As space also reserves the some space.

ii-                 chr(): it gets any number as parameter and it returns the character of that given asci code.
<?php
            $val = 87;
            echo chr($val);
?>
The result will be `W`, because 87 is the asci code of W letter.

iii-               ord(): it takes any single character as a parameter and returns the asci code of that character.
Extending above example, we have passed 87 as parameter and results W and if in here ord() if we pass `W` as parameter the result would be 87 because the asci code of W is 87 or any single character you write within braces in ord function will be printed out asci code of hat character.
Example:
<?php
      $val = “W”;
      echo ord($val);
?>
The result will be 87.

iv-               substr(): this function returns the part of string or breaks the string into our requirement.
syntax:
substr(string, start, length)
length is optional.
Let’s have an example:

<?php
      $name = “hello world, my name is php”;
      echo substr( $name, 6)
?>
Output will be `world, my name is php`
The above code will result from 6th position of character up to the end of string because length we have not defined. If we have defined length let suppose 7, then result will could come from 6th position to 7 characters further.
`world, ` this could come the result because remember space is also counted as a character. It reserves the space of single character.

v-                 round(): round function rounds off the number to make number smaller and more understandable.
<?php
      echo round(87.6)
// result will be 88
?>
vi-               ceil(): function will convert any of the number into next coming bigger number
<?php
echo ciel(-7.6)
// result will be -6
?>

vii-             floor(): converts the number into previous smaller number.
<?php
      echo floor(-7.6)
// result will be -8
?>
Hope you got the concept about built-in functions, very easy and comfortable just like these there are hundreds of PHP built-in functions you can see and use them according to your need and practice them.

Thanks Guys. Any thing missing or any question from this topic you can comment below, I will be trying to solve and answer your question.
Our Next topic will be `Array`.
Good Luck J

No comments:

Post a Comment