Learn How To Use Strpos Function With Example Using PHP

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

strpos() function  find the position of the first occurrence of a substring in a string.

PHP strpos Function with example

Syntax of strpos() function and Usage.

strpos(input_str,search_str,start)

Parameter Values
input_str   ->The string to search in.

search_str  ->Specifies the string to search.

start       ->This refers to the position of the string from where the search must begin.

Let's learn

1.Create strpos()

strpos("Easy to learn in BAJARANGISOFT","learn",5)


2.Print string using strpos() function.
echo strpos("Easy to learn in BAJARANGISOFT","learn")

Example(1)
<?php
echo strpos("Easy to learn in BAJARANGISOFT","learn");
?>


Complete Code of strpos() Function:
<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP string position 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">
</head>
<body>
<div class="container">
    <div class="text-center">
        <h1>PHP strpos() Function</h1>
    </div>
    <br>
    <h2>The strpos() function  find the position of the first occurrence of a substring in a string.</h2>
    <div class="well">
        <?php
        echo "<h4>".strpos("Easy to learn in BAJARANGISOFT","learn",5)."</h4>";
        ?>
    </div>
    <br>
</div>
</body>
</html>

Related Post