Session 3:
PHP String Function:
The string functions allow you to manipulate strings.
Following are the examples of important PHP String Function.
Following are the examples of important PHP String Function.
Examples:
1) explode() : breaks a string into an array.
<?php
$str1="PHP is the most powerful programming language in the world";
$str2="PHP,MYSQL,JavaScript,AJAX,C,C++,VB,VC";
$str3=explode(" ",$str1);
$strarr=count($str3);
for($i=0;$i<$strarr;$i++)
{
echo $str3[$i]."<br />";
}
?>
$str1="PHP is the most powerful programming language in the world";
$str2="PHP,MYSQL,JavaScript,AJAX,C,C++,VB,VC";
$str3=explode(" ",$str1);
$strarr=count($str3);
for($i=0;$i<$strarr;$i++)
{
echo $str3[$i]."<br />";
}
?>
2) The str_word_count() function counts the number of words in a string.
<?php
$str1="php is the most powerful programming language in the world";
$str2=str_word_count($str1);
echo $str2;
?>
$str1="php is the most powerful programming language in the world";
$str2=str_word_count($str1);
echo $str2;
?>
3) The strtolower() function converts a string to lowercase letters
<?php
$str1="PHP is the MOST powerful programming language in the world";
$str2=strtolower($str1);
echo $str2;
?>
$str1="PHP is the MOST powerful programming language in the world";
$str2=strtolower($str1);
echo $str2;
?>
4) The md() function calculates the MD5 hash of a string
<?php
$str1="PHP is the most powerful programming language in the world";
$str2=md5($str1);
echo $str2;
?>
$str1="PHP is the most powerful programming language in the world";
$str2=md5($str1);
echo $str2;
?>
5) The substr() function returns a part of a string
<?php
$str1="PHP is the most powerful programming language in the world";
$str2=substr($str1,10,10);
echo $str2;
?>
$str1="PHP is the most powerful programming language in the world";
$str2=substr($str1,10,10);
echo $str2;
?>
6) The trim() function strips whitespace from both sides of a string
<?php
$fname="";
if(isset($_POST["submit"]))
{
$fname=$_POST["name"];
echo "without ltrim :*".$fname."*<br />";
$str1=ltrim($fname);
echo "with Ltrim :*".$str1."*<br />";
$str2=trim($fname);
echo "with Trim :*".$str2."*<br />";
$str3=rtrim($fname);
echo "with Rtrim :*".$str3."*<br />";
}
?>
<html>
<body>
<form action="" name="stringform" method="post">
First Name:<input type="text" name="name" value="" />
<input type="submit" value="submit" name="submit" />
</body>
</html>
$fname="";
if(isset($_POST["submit"]))
{
$fname=$_POST["name"];
echo "without ltrim :*".$fname."*<br />";
$str1=ltrim($fname);
echo "with Ltrim :*".$str1."*<br />";
$str2=trim($fname);
echo "with Trim :*".$str2."*<br />";
$str3=rtrim($fname);
echo "with Rtrim :*".$str3."*<br />";
}
?>
<html>
<body>
<form action="" name="stringform" method="post">
First Name:<input type="text" name="name" value="" />
<input type="submit" value="submit" name="submit" />
</body>
</html>
7) The strstr() function finds the first occurrence of a string inside another string (case-sensitive)
<?php
$str1="PHP is the most powerful programming language in the world";
$str2=strstr($str1,"most");
echo $str2;
?>
$str1="PHP is the most powerful programming language in the world";
$str2=strstr($str1,"most");
echo $str2;
?>
8) The ucfirst() function converts the first character of a string to uppercase
<?php
$str1="php is the most powerful programming language in the world";
$str2=ucfirst($str1);
echo $str2;
?>
$str1="php is the most powerful programming language in the world";
$str2=ucfirst($str1);
echo $str2;
?>
9) The ucwords() function converts the first character of each word in a string to uppercase
<?php
$str1="php is the most powerful programming language in the world";
$str2=ucwords($str1);
echo $str2;
?>
$str1="php is the most powerful programming language in the world";
$str2=ucwords($str1);
echo $str2;
?>
10) The strtoupper() function converts a string to uppercase letters
<?php
$str1="PHP is the most powerful programming language in the world";
$str2=strtoupper($str1);
echo $str2;
?>
$str1="PHP is the most powerful programming language in the world";
$str2=strtoupper($str1);
echo $str2;
?>
1.Basics of Php:Variables,Operators
2.Loops,Conditional Statements
And when you begin tossing $20 at clientele for spreading
ReplyDeletethe word about your DJ business, they will commence marketing
for you a lot more often. Tron's original soundtrack by Wendy Carlos never left an impression with me either even being a film score and electronica fanatic. The video then provides a background to how the stain came to be, from the growing of the tomato plant, to his mom making him homemade spaghetti sauce, and everything in between.
Feel free to visit my web site ... random access Memories daft punk free download rar
In the beginning of the 11th Century the represents of Christianity is able
ReplyDeleteto banned the duel form einvigi and holmgangr as lawfully accepted means to solve a dispute,
and at the same time the berserkr and the beserksgangr was made illegal.
The adobe reader is what you need to download e - Book in PDF format.
So, without spending any money (assuming you already had a computer),
you have your equipment.
Stop by my weblog: free pdf ebook download
Anyhow, the Somanabolic Muscle Maximizer is unique from
ReplyDeletethe feeling that it's not a normal exercise application but a specific one particular which helps various folk attain their diverse health and fitness targets. When you've got added
your details to the program, it is going to give you
3 diets to check out. Whenever upgrades became ready
you'll fully grasp this totally free no matter what quantity of money cost to establish them.
my site - Somanabolic Muscle Maximizer Review