Monday, 16 November 2015

10_strlen()

strlen()


Find the length of the string


< ? Php
$string1=”HArshida D Parmar”;
echo strlen($string1);
? >


It is used to count the character from the string…


Also used to loop through in to the php… Loop through each character…And for looping either you can use for, while or do_while loop. So let’s take a example of LOOP THROUGH…


< ? Php
$string1=”HArshida D Parmar”;
echo strlen($string1);
for($x=1;$x<=strlen($string1);$x++){
echo $x; }
? >



Upper and Lower Case Conversion


< ? Php $string1=”Something is here HArshida”; $str_low=strtolower($string1); Echo $str_low; ? >


strtolower() function will convert all the character into the lower case.


< ? Php $string1=”Something is here HArshida”; $str_low=strtouper($string1); Echo $str_low; ? >


strtoupper() function will convert all the character into the UPPER CASE.


Now question arise why we use this function so let’s demonstrate


< ? Php
If(isset($_GET[“user_name”]) && !empty($_GET[“user_name”])) {
//!empty () means NOT EMPTY…
$user_name=$_GET[“user_name”];
if(strtolower($user_name)==”harshida”) {
echo ”harshida d parmar you are the best person …”;
}
? >


Name:



Now when you run the page you can see that inside the textbox user can enter the name in lower or upper case… but if we want to compare the data based on lower case then what we should do now ????


So using strtolower() function will convert the value of textbox to lower case… and then check using if condition… if textbox value is either Harshida or HARSHIDA or harshida… the program will give the O/P “harshida d parmar you are the best person…”



No comments:

Post a Comment