PHP strpos() string function



The strpos() function in PHP

The strpos() function used to searches the specific text in given string, if found then return start position of matches text, other wise returns false.

strpos() function syntax

strpos(“string”, “search string”);

PHP strpos() function example

<?php
echo "The strpos() answer = ". strpos("Hello Meera Academy","Meera");
?>

The out put of strpos() is:

The strpos() answer = 6

The strpos() string function php from  example

<html>
<head>
<title>PHP strpos() Function</title>
</head>
<body>

<FORM method="POST" action="firstexample.php">

Name : <input type="text" name="name"> <br/>

<br/>
<input type="submit" name="Submit1" value="String Position">

</FORM>

<?php
if(isset($_POST['Submit1']))
{
echo "The strpos() answer = ". strpos($_POST["name"],"Meera");
}
?>

</body>
</html>

The php strpos() string function output is :

PHP strpos() string function
PHP strpos() string function

Leave a Reply

Your email address will not be published. Required fields are marked *