PHP STRING FUNCTION with example

PHP STRING FUNCTIONS

PHP support a large number of built in string functions.here we consider the basic function for

inspecting

modifying

printing string

SL NO NAME description example
1

Strlen()

To get string length


return the length of the string on succes,and 0 if the string is empty

$str = 'abcdef';
echo strlen($str);

the output will be 6
2

Strops()

FIND position of first occurense of a string


item to be searched . if item is not a string .
it is a converted to and integer and appliedd as the ordinal value of a character


$mystring ='abc';
$findme = 'a';
$pos = $strpos($mystring,$findme);

the output will 0
3

strrpos()

Find the posistion of the last occurense of a substring in a string


Return the numeric position of the last occurense of data in the string ,
return false if the item was not found
$mystring ='abcda';
$findme = 'a';
$pos = strrpos($mystring,$findme);
the output will 4
4

Strcmp()

Binery safe string comparing

strcmp ($str1,$str2)
This function return < 0 if str1 is less than str2;>0 if str1 is
greater than str2, and 0 if they are equal note that this comparison is case sensitive
$string1 = "abc";
$string2 = "abcd";
$value = strcmp ($string1,$string2);
if($value < 0)
{
echo "string1 is lesthan $string2";
}
else
{
echo "string1 is greaterthan $string2";

} 
the output will be string1 is lesthan abcd

FEBINOCCI series in PHP

Here we are going to understand how can calculate febinocci series in a LIMIT.

First we should know that what is FEBINOCCI series?

“The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,... The next number is found by adding up the two numbers before it. Similarly, the 3 is found by adding the two numbers before it (1+2)”


HERE the series come by
0 + 0 = 0
0        +  1 = 1
1        +  1 = 2
2        + 1 = 3
And so on

Now we can go to program program

<! febinocii series > {to create comment in html}
<html>
<body>
<h1>febinocci series</h1>
<form name="form1" method="POST" action = " ">
<input type="text" name="limit">
<input type="submit" name="sub" value="submit">
<form>
</body>
</html>

<?php
if(isset($_POST['sub']))
{
$first=0;
$b=0;
$limit= $_POST['limit'];
for($a=1;$a<=$limit;$a++)
{
$b=$first +$a;
$first =$b;
echo   "<br/>" . $first."<br/>" ;
}
}
?>


Are you confusing!
Don’t worry here I use    echo “  ”;  it is used to write html on php
NOW TRY IN YOUR COMPUTER

THE OUT PUT IS HERE

 



click to view datas on database

<HTML>
<head>
</head>
<body>
<h1>student registration</h1>
<table border="1px">
<tr>
<TD>add</TD>
<TD>
    view<TD/>
<TD>
    edit
    </TD>
</tr>

<tr>
<TD><a href="student.php">click here to add new</a></td>

<TD>
<a href="view.php"> click here to view</a>
</TD>

<TD>
<a href="edit.php"> click here to edit</a>
</TD>
</tr>
</table>
</body>
</HTML>