Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

What is the String?

The string is a collection of char, String contains all data using a single stream. String indexing will be similar to an array, it will start from 0 to strlen()-1, strlen() is the predefined method that will return the total number of char in String.


for example  

$x = "hello";

echo $x;

but indexing will be started from 0 to 4.

echo $x[2];   //l

 
 

in PHP We can declare String using a single quote ' ' and double quote " " both. Single quote string provides pure string value means the variable value will not be rendered. but double quote String " " provide normal string data means the variable value will be rendered.


for example


$x = 'abc ';
echo '$x';   o/p $x
$x= "abc";

echo "$x";     o/p abc



...............................................................................................................................................

Predefine function of String:-

1) strlen() :-  it return String size

   $x = "hello";
echo strlen($x);


2) strrev():-
  it will reverse String


Example of String Function

  $x = "hello";
echo strrev($x);


3) strtoupper():-  Convert string into upper case 

$x = "hello";
echo strtoupper($x).

4) strtolower():-  Convert string into lower case 

$x = "hello";
echo strtolower($x).


5 )str_replace():-  We can replace particular char from String.


$x = "hello";

echo str_replace('h','m' , $x);





5) implode():-  It is used to convert array to String.

$x = array("c","c++","java","php");

echo implode(' ', $x);  //first parameter glue(symbol) and second parameter array




6)  explode():-  It is used to convert String to the array.

$s = "C,C++,JAVA,PHP,.NET,SQL";

$arr = explode(",",$s);

print_r($arr);

   


Complete String based program:-

<?php

$x = "hello";
echo strlen($x)."<br>";
echo strrev($x)."<br>";
echo strtoupper($x)."<br>";
echo strtolower($x)."<br>";
echo str_replace('h','m' , $x);
echo "<br>";
$x = array("c","c++","java","php");

echo implode(' ', $x);

$s = "C,C++,JAVA,PHP,.NET,SQL";

$arr = explode(",",$s);

print_r($arr);

?>


Assignments:-

1)  WAP to check that string is palindrome or not?

2)  WAP  to convert string in the opposite case?

3) WAP to validate mobile?

4)  WAP to validate email?

5)  WAP to validate the name that it should be alphabets?

6)  WAP to validate password that it is weak, strong, or medium?

weak:-  if no special char and length is less then 6
medium:-  less than two special char and length above 6

Strong:- four special char, one upper case, one number length about 8 then 






10 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. MANSI DUBEY



    $string="madam";

    if ($string == strrev($string)) {
    echo "string is palindrome";
    }
    else
    echo "string is not palindrome" ;

    ReplyDelete
  2. MANSI DUBEY



    $x="php";
    if ($x == strtolower($x) ) {
    echo strtoupper($x);
    }
    if ($x == strtoupper($x) ) {
    echo strtolower($x);
    }

    ReplyDelete
  3. function Palindrome($string){
    if (strrev($string) == $string){
    return 1;
    }
    else{
    return 0;
    }
    }
    $original = "DAD";
    if(Palindrome($original)){
    echo "Palindrome";
    }
    else {
    echo "Not a Palindrome";
    }

    ReplyDelete
  4. print"To check string is palindrome or not";

    echo "
    ";
    echo "
    ";

    $x = "MALAYALAM";

    echo $x;

    echo "
    ";
    echo "
    ";

    $y = strrev($x);

    if($x==$y) {
    echo "String [ $x ] is Palindrome";
    }

    else {
    echo "string [ $x ] is not Palindrome";
    }

    ReplyDelete
  5. Shubham Nandwal
    Palindrome or Not.

    $st="nayan";
    $str=strrev($st);

    if($st==$str)
    {
    echo "THIS IS PALINDROME";
    }
    else
    {
    echo "THIS IS NOT PALINDROME";
    }

    ReplyDelete
  6. Shubham Nandwal
    Convert String In Opposite Case.

    $st=("shiva concept");
    $stu=strtoupper($st);
    $stl=strtolower($st);
    if($st==$stu)
    {
    echo strtolower($st);
    }
    else
    {
    echo strtoupper($st);
    }

    ReplyDelete
  7. Shubham Nandwal
    Validate Mobile

    $st="9827212345";

    if(strlen($st)=='10')
    {
    echo "YOUR MOBILE NO. IS $st";
    }
    else{
    echo "PLEASE ENTER A VALID 10 DIGIT MOBILE NO.";
    }

    ReplyDelete
  8. Shubham Nandwal

    Validate E-mail Id

    $em="abcd_123@gmail.com";
    if(filter_var($em,FILTER_VALIDATE_EMAIL))
    {
    echo "YOUR E-MAIL ID IS" ,"
    ","
    ", "$em";
    }
    else
    {
    echo "PLEASE ENTER A VALID E-MAIL ID";
    }

    ReplyDelete
  9. Shubham Nandwal
    Name Validation(Should Be Alphabetic)

    $st = 'Shubham Nandwal';

    if(preg_match("/^[a-zA-Z ,]+$/", $st))
    {
    echo "$st";
    }
    else
    {
    echo "This Text Contents Non Alphabetic Characters";
    }

    ReplyDelete
  10. Shubham Nandwal
    Password Validation(Strong/Medium/Weak)

    $pass = 'Shiva*123';

    $str=strlen($pass);

    if((preg_match("/^[a-zA-Z @ # $ % * _ - 0-9]+$/", $pass)) && $str>8)
    {
    echo "Password Is Strong";
    }
    elseif(preg_match("/^[a-zA-Z @ # $ % * _ - 0-9]+$/", $pass) && $str>6)
    {
    echo "Password Is Medium";
    }
    elseif($str<6 or !preg_match("/^[a-zA-Z ,]+$/", $pass))
    {
    echo "Password Is Weak";
    }

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post