Learn How To Use Stristr Function With Example In PHP

admin_img Posted By Bajarangi soft , Posted On 24-09-2020

The stristr() function searches for the first occurrence of a string inside another string.

stristr_Function


This function returns the rest of the string, or FALSE, if the string to search for is not found.
This function is case-insensitive.


Syntax of stristr() function and Usage:

stristr(string,search,before_search)


Parameter Values

string          -> Specifies the string to search.

search          -> Specifies the string to search for.
                   If this parameter is a number, it will search for the character matching the ASCII value of the number.

before_search   -> A boolean value whose default is "false". If set to "true",
                   it returns the part of the string before the first occurrence of the search parameter.


Let's learn

1.Create stristr()

stristr("Hello world!,Welcome to BAJARANGISOFT","s")


2.Print string using stristr() function.

echo  stristr("Hello world!,Welcome to BAJARANGISOFT","s");


Example(1)

<?php
    echo stristr("Hello world!,Welcome to BAJARANGISOFT","s");
?>


Example(2)

<?php
   echo stristr("Hello world!,Welcome to BAJARANGISOFT","s",true);
?>


Example(3)

<?php
  echo stristr("Hello world!,Welcome to BAJARANGISOFT",111);
?>


Complete Code of stristr() Function:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP stristr function</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div class="text-center">
        <h1>PHP stristr() Function</h1>
    </div>
    <br>
    <h2>The stristr() function searches for the first occurrence of a string inside another string.</h2>
    <div class="well">
        <?php
        echo "<h4>". stristr("Hello world!,Welcome to BAJARANGISOFT","s")."</h4>";
        echo "<h4>". stristr("Hello world!,Welcome to BAJARANGISOFT","s",true)."</h4>";
        echo "<h4>". stristr("Hello world!,Welcome to BAJARANGISOFT",111)."</h4>";
        ?>
    </div>
    <br>
</div>
</body>
</html>

Related Post